X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-posix_spawn_file_actions_adddup2.c;h=fe33c025896db1d88d590615b53e2ac2c8287045;hb=74540d44dc16bfd3546e39ae2d7262f32a4147ab;hp=f6173043cae9983106e1aac9a47df9a5f19ba4e7;hpb=9fc81090f6c5590bd1b0e0fa5087577a2ee43a3e;p=gnulib.git diff --git a/tests/test-posix_spawn_file_actions_adddup2.c b/tests/test-posix_spawn_file_actions_adddup2.c index f6173043c..fe33c0258 100644 --- a/tests/test-posix_spawn_file_actions_adddup2.c +++ b/tests/test-posix_spawn_file_actions_adddup2.c @@ -23,12 +23,29 @@ SIGNATURE_CHECK (posix_spawn_file_actions_adddup2, int, (posix_spawn_file_actions_t *, int, int)); #include +#include +#include #include "macros.h" +/* Return a file descriptor that is too big to use. + Prefer the smallest such fd, except use OPEN_MAX if it is defined + and is greater than getdtablesize (), as that's how OS X works. */ +static int +big_fd (void) +{ + int fd = getdtablesize (); +#ifdef OPEN_MAX + if (fd < OPEN_MAX) + fd = OPEN_MAX; +#endif + return fd; +} + int main (void) { + int bad_fd = big_fd (); posix_spawn_file_actions_t actions; ASSERT (posix_spawn_file_actions_init (&actions) == 0); @@ -40,7 +57,7 @@ main (void) } { errno = 0; - ASSERT (posix_spawn_file_actions_adddup2 (&actions, 10000000, 2) == EBADF); + ASSERT (posix_spawn_file_actions_adddup2 (&actions, bad_fd, 2) == EBADF); } { errno = 0; @@ -48,7 +65,7 @@ main (void) } { errno = 0; - ASSERT (posix_spawn_file_actions_adddup2 (&actions, 2, 10000000) == EBADF); + ASSERT (posix_spawn_file_actions_adddup2 (&actions, 2, bad_fd) == EBADF); } return 0;