X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-fchdir.c;h=0375c317d82e8794c7d5172d7a4957e32a9b104f;hb=7d7ec7650cd840f005ddd6dd886dd1036802fd63;hp=b361d0d61693e733b05c646820b05871f429d964;hpb=8fc864a0b873beea0c37acb7898a8cf5f497fb4e;p=gnulib.git diff --git a/tests/test-fchdir.c b/tests/test-fchdir.c index b361d0d61..0375c317d 100644 --- a/tests/test-fchdir.c +++ b/tests/test-fchdir.c @@ -1,5 +1,5 @@ /* Test changing to a directory named by a file descriptor. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,26 +20,19 @@ #include +#include "signature.h" +SIGNATURE_CHECK (fchdir, int, (int)); + #include #include -#include #include #include -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ - while (0) +#include "cloexec.h" +#include "macros.h" int -main () +main (void) { char *cwd = getcwd (NULL, 0); int fd = open (".", O_RDONLY); @@ -67,23 +60,36 @@ main () ASSERT (chdir (".." + 1 - i) == 0); ASSERT (fchdir (fd) == 0); { - size_t len = strlen (cwd) + 1; - char *new_dir = malloc (len); - ASSERT (new_dir); - ASSERT (getcwd (new_dir, len) == new_dir); - ASSERT (strcmp (cwd, new_dir) == 0); - free (new_dir); + size_t len = strlen (cwd) + 1; + char *new_dir = malloc (len); + ASSERT (new_dir); + ASSERT (getcwd (new_dir, len) == new_dir); + ASSERT (strcmp (cwd, new_dir) == 0); + free (new_dir); } /* For second iteration, use a cloned fd, to ensure that dup - remembers whether an fd was associated with a directory. */ + remembers whether an fd was associated with a directory. */ if (!i) - { - int new_fd = dup (fd); - ASSERT (0 <= new_fd); - ASSERT (close (fd) == 0); - fd = new_fd; - } + { + int new_fd = dup (fd); + ASSERT (0 <= new_fd); + ASSERT (close (fd) == 0); + ASSERT (dup2 (new_fd, fd) == fd); + ASSERT (close (new_fd) == 0); + ASSERT (dup_cloexec (fd) == new_fd); + ASSERT (dup2 (new_fd, fd) == fd); + ASSERT (close (new_fd) == 0); + ASSERT (fcntl (fd, F_DUPFD_CLOEXEC, new_fd) == new_fd); + ASSERT (close (fd) == 0); + ASSERT (fcntl (new_fd, F_DUPFD, fd) == fd); + ASSERT (close (new_fd) == 0); +#if GNULIB_TEST_DUP3 + ASSERT (dup3 (fd, new_fd, 0) == new_fd); + ASSERT (dup3 (new_fd, fd, 0) == fd); + ASSERT (close (new_fd) == 0); +#endif + } } free (cwd);