- int fd[2];
- char *argv[4];
- pid_t pid;
- char buffer[2] = { 'a', 't' };
-
- /* Set up child. */
- argv[0] = (char *) argv0;
- argv[1] = (char *) "child";
- argv[2] = (char *) (stderr_closed ? "1" : "0");
- argv[3] = NULL;
- pid = create_pipe_bidi (argv0, argv0, argv, false, true, true, fd);
- ASSERT (0 <= pid);
- ASSERT (STDERR_FILENO < fd[0]);
- ASSERT (STDERR_FILENO < fd[1]);
-
- /* Push child's input. */
- ASSERT (write (fd[1], buffer, 1) == 1);
- ASSERT (close (fd[1]) == 0);
-
- /* Get child's output. */
- ASSERT (read (fd[0], buffer, 2) == 1);
-
- /* Wait for child. */
- ASSERT (wait_subprocess (pid, argv0, true, false, true, true, NULL) == 0);
- ASSERT (close (fd[0]) == 0);
-
- /* Check the result. */
- ASSERT (buffer[0] == 'b');
- ASSERT (buffer[1] == 't');
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ HANDLE h = (HANDLE) _get_osfhandle (fd);
+ DWORD flags;
+ ASSERT (GetHandleInformation (h, &flags));
+ return (flags & HANDLE_FLAG_INHERIT) == 0;
+#else
+ int flags;
+ ASSERT ((flags = fcntl (fd, F_GETFD)) >= 0);
+ return (flags & FD_CLOEXEC) != 0;
+#endif