X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-fcntl.c;h=23a0dba0df3a4230e3c3b3445522a58d3cf91d6e;hb=1bec204c2960db4a71418ddcec179a2d1e05095f;hp=c5a931c09d0d6c8f2581adfa9f5e809804d7af90;hpb=38f87b03c2763bb2af05ae98905b0ac8ba55b3eb;p=gnulib.git diff --git a/tests/test-fcntl.c b/tests/test-fcntl.c index c5a931c09..23a0dba0d 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-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 @@ -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,29 +37,13 @@ #endif #include "binary-io.h" - -/* Use O_CLOEXEC if available, but test works without it. */ -#ifndef O_CLOEXEC -# define O_CLOEXEC 0 -#endif +#include "macros.h" #if !O_BINARY # define setmode(f,m) zero () 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 +140,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 +205,7 @@ check_flags (void) } int -main (int argc, char **argv) +main (void) { const char *file = "test-fcntl.tmp"; int fd; @@ -241,8 +220,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 +312,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; }