tests: port large-fd POSIX spawn tests to OS X
[gnulib.git] / tests / test-posix_spawn_file_actions_adddup2.c
index d728eff..fe33c02 100644 (file)
@@ -23,14 +23,29 @@ SIGNATURE_CHECK (posix_spawn_file_actions_adddup2, int,
                  (posix_spawn_file_actions_t *, int, int));
 
 #include <errno.h>
+#include <limits.h>
 #include <unistd.h>
 
 #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 = getdtablesize ();
+  int bad_fd = big_fd ();
   posix_spawn_file_actions_t actions;
 
   ASSERT (posix_spawn_file_actions_init (&actions) == 0);