X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-dup-safer.c;h=4dcd752ed26bc27cace99337c3e05082b2fc978f;hb=69770559f5bf198928150ac8162734d7f6b99c82;hp=24cc9e5f377f46f97403b83236cef29dcb23b0dc;hpb=2d4d7d9d00fe33b6f5291e00a30b6c1016775b74;p=gnulib.git diff --git a/tests/test-dup-safer.c b/tests/test-dup-safer.c index 24cc9e5f3..4dcd752ed 100644 --- a/tests/test-dup-safer.c +++ b/tests/test-dup-safer.c @@ -1,5 +1,5 @@ /* Test that dup_safer leaves standard fds alone. - Copyright (C) 2009 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 @@ -24,51 +24,40 @@ #include #include #include -#include -#include +#include #include "binary-io.h" #include "cloexec.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 +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" #endif #if !O_BINARY # define setmode(f,m) zero () static int zero (void) { return 0; } #endif -#ifndef O_CLOEXEC -# define O_CLOEXEC 0 -#endif /* This test intentionally closes stderr. So, we arrange to have fd 10 (outside the range of interesting fd's during the test) set up to duplicate the original stderr. */ #define BACKUP_STDERR_FILENO 10 -static FILE *myerr; +#define ASSERT_STREAM myerr +#include "macros.h" -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (myerr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (myerr); \ - abort (); \ - } \ - } \ - while (0) +static FILE *myerr; /* Return true if FD is open. */ 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; @@ -85,7 +74,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); @@ -119,6 +108,7 @@ main (void) { int i; int fd; + int bad_fd = getdtablesize (); /* We close fd 2 later, so save it in fd 10. */ if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO @@ -141,7 +131,7 @@ main (void) ASSERT (dup (-1) == -1); ASSERT (errno == EBADF); errno = 0; - ASSERT (dup (10000000) == -1); + ASSERT (dup (bad_fd) == -1); ASSERT (errno == EBADF); close (fd + 1); errno = 0;