diff options
Diffstat (limited to 'gnulib-tests/test-fcntl.c')
-rw-r--r-- | gnulib-tests/test-fcntl.c | 81 |
1 files changed, 74 insertions, 7 deletions
diff --git a/gnulib-tests/test-fcntl.c b/gnulib-tests/test-fcntl.c index 6b4ad09..67d1b41 100644 --- a/gnulib-tests/test-fcntl.c +++ b/gnulib-tests/test-fcntl.c @@ -1,7 +1,5 @@ -/* -*- buffer-read-only: t -*- vi: set ro: */ -/* DO NOT EDIT! GENERATED AUTOMATICALLY! */ /* Test of fcntl(2). - Copyright (C) 2009-2011 Free Software Foundation, Inc. + Copyright (C) 2009-2013 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 @@ -33,9 +31,11 @@ SIGNATURE_CHECK (fcntl, int, (int, int, ...)); #include <unistd.h> #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -/* Get declarations of the Win32 API functions. */ +/* Get declarations of the native Windows API functions. */ # define WIN32_LEAN_AND_MEAN # include <windows.h> +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" #endif #include "binary-io.h" @@ -51,7 +51,7 @@ static bool is_open (int fd) { #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - /* On Win32, the initial state of unassigned standard file + /* On native Windows, the initial state of unassigned standard file descriptors is that they are open but point to an INVALID_HANDLE_VALUE, and there is no fcntl. */ return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE; @@ -68,7 +68,7 @@ static bool is_inheritable (int fd) { #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - /* On Win32, the initial state of unassigned standard file + /* On native Windows, the initial state of unassigned standard file descriptors is that they are open but point to an INVALID_HANDLE_VALUE, and there is no fcntl. */ HANDLE h = (HANDLE) _get_osfhandle (fd); @@ -314,7 +314,7 @@ main (void) ASSERT (is_mode (fd + 2, O_TEXT)); ASSERT (close (fd + 2) == 0); - /* Test F_GETFD. */ + /* Test F_GETFD on invalid file descriptors. */ errno = 0; ASSERT (fcntl (-1, F_GETFD) == -1); ASSERT (errno == EBADF); @@ -324,6 +324,8 @@ main (void) errno = 0; ASSERT (fcntl (10000000, F_GETFD) == -1); ASSERT (errno == EBADF); + + /* Test F_GETFD, the FD_CLOEXEC bit. */ { int result = fcntl (fd, F_GETFD); ASSERT (0 <= result); @@ -335,6 +337,71 @@ main (void) ASSERT (close (fd + 1) == 0); } +#ifdef F_SETFD + /* Test F_SETFD on invalid file descriptors. */ + errno = 0; + ASSERT (fcntl (-1, F_SETFD, 0) == -1); + ASSERT (errno == EBADF); + errno = 0; + ASSERT (fcntl (fd + 1, F_SETFD, 0) == -1); + ASSERT (errno == EBADF); + errno = 0; + ASSERT (fcntl (10000000, F_SETFD, 0) == -1); + ASSERT (errno == EBADF); +#endif + +#ifdef F_GETFL + /* Test F_GETFL on invalid file descriptors. */ + errno = 0; + ASSERT (fcntl (-1, F_GETFL) == -1); + ASSERT (errno == EBADF); + errno = 0; + ASSERT (fcntl (fd + 1, F_GETFL) == -1); + ASSERT (errno == EBADF); + errno = 0; + ASSERT (fcntl (10000000, F_GETFL) == -1); + ASSERT (errno == EBADF); +#endif + +#ifdef F_SETFL + /* Test F_SETFL on invalid file descriptors. */ + errno = 0; + ASSERT (fcntl (-1, F_SETFL, 0) == -1); + ASSERT (errno == EBADF); + errno = 0; + ASSERT (fcntl (fd + 1, F_SETFL, 0) == -1); + ASSERT (errno == EBADF); + errno = 0; + ASSERT (fcntl (10000000, F_SETFL, 0) == -1); + ASSERT (errno == EBADF); +#endif + +#ifdef F_GETOWN + /* Test F_GETOWN on invalid file descriptors. */ + errno = 0; + ASSERT (fcntl (-1, F_GETOWN) == -1); + ASSERT (errno == EBADF); + errno = 0; + ASSERT (fcntl (fd + 1, F_GETOWN) == -1); + ASSERT (errno == EBADF); + errno = 0; + ASSERT (fcntl (10000000, F_GETOWN) == -1); + ASSERT (errno == EBADF); +#endif + +#ifdef F_SETOWN + /* Test F_SETFL on invalid file descriptors. */ + errno = 0; + ASSERT (fcntl (-1, F_SETOWN, 0) == -1); + ASSERT (errno == EBADF); + errno = 0; + ASSERT (fcntl (fd + 1, F_SETOWN, 0) == -1); + ASSERT (errno == EBADF); + errno = 0; + ASSERT (fcntl (10000000, F_SETOWN, 0) == -1); + ASSERT (errno == EBADF); +#endif + /* Cleanup. */ ASSERT (close (fd) == 0); ASSERT (unlink (file) == 0); |