X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-fcntl.c;h=71dfb9869fb665d94888749fb991dfba1c500775;hb=de4d0a383be20eb6cbeb09ecbd66a5514779b914;hp=c5a931c09d0d6c8f2581adfa9f5e809804d7af90;hpb=38f87b03c2763bb2af05ae98905b0ac8ba55b3eb;p=gnulib.git diff --git a/tests/test-fcntl.c b/tests/test-fcntl.c index c5a931c09..71dfb9869 100644 --- a/tests/test-fcntl.c +++ b/tests/test-fcntl.c @@ -1,5 +1,5 @@ /* Test of fcntl(2). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009, 2010 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 @@ -21,12 +21,13 @@ /* Specification. */ #include +#include "signature.h" +SIGNATURE_CHECK (fcntl, int, (int, int, ...)); + /* Helpers. */ #include #include #include -#include -#include #include #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ @@ -36,6 +37,7 @@ #endif #include "binary-io.h" +#include "macros.h" /* Use O_CLOEXEC if available, but test works without it. */ #ifndef O_CLOEXEC @@ -47,18 +49,6 @@ static int zero (void) { return 0; } #endif -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ - while (0) - /* Return true if FD is open. */ static bool is_open (int fd) @@ -155,22 +145,16 @@ check_flags (void) { switch (0) { -#ifdef F_DUPFD case F_DUPFD: -# if F_DUPFD -# endif +#if F_DUPFD #endif -#ifdef F_DUPFD_CLOEXEC case F_DUPFD_CLOEXEC: -# if F_DUPFD_CLOEXEC -# endif +#if F_DUPFD_CLOEXEC #endif -#ifdef F_GETFD case F_GETFD: -# if F_GETFD -# endif +#if F_GETFD #endif #ifdef F_SETFD @@ -226,7 +210,7 @@ check_flags (void) } int -main (int argc, char **argv) +main (void) { const char *file = "test-fcntl.tmp"; int fd; @@ -241,8 +225,6 @@ main (int argc, char **argv) } check_flags (); -#if HAVE_FCNTL - /* Assume std descriptors were provided by invoker, and ignore fds that might have been inherited. */ fd = creat (file, 0600); @@ -335,11 +317,30 @@ main (int argc, char **argv) ASSERT (is_mode (fd + 2, O_TEXT)); ASSERT (close (fd + 2) == 0); + /* Test F_GETFD. */ + errno = 0; + ASSERT (fcntl (-1, F_GETFD) == -1); + ASSERT (errno == EBADF); + errno = 0; + ASSERT (fcntl (fd + 1, F_GETFD) == -1); + ASSERT (errno == EBADF); + errno = 0; + ASSERT (fcntl (10000000, F_GETFD) == -1); + ASSERT (errno == EBADF); + { + int result = fcntl (fd, F_GETFD); + ASSERT (0 <= result); + ASSERT ((result & FD_CLOEXEC) == FD_CLOEXEC); + ASSERT (dup (fd) == fd + 1); + result = fcntl (fd + 1, F_GETFD); + ASSERT (0 <= result); + ASSERT ((result & FD_CLOEXEC) == 0); + ASSERT (close (fd + 1) == 0); + } + /* Cleanup. */ ASSERT (close (fd) == 0); ASSERT (unlink (file) == 0); -#endif /* HAVE_FCNTL */ - return 0; }