2 Copyright (C) 2009-2011 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
22 #include "signature.h"
23 SIGNATURE_CHECK (pipe2, int, (int[2], int));
28 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
29 /* Get declarations of the Win32 API functions. */
30 # define WIN32_LEAN_AND_MEAN
34 #include "binary-io.h"
36 #include "nonblocking.h"
38 /* Return true if FD is open. */
42 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
43 /* On Win32, the initial state of unassigned standard file
44 descriptors is that they are open but point to an
45 INVALID_HANDLE_VALUE, and there is no fcntl. */
46 return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE;
49 # error Please port fcntl to your platform
51 return 0 <= fcntl (fd, F_GETFL);
55 /* Return true if FD is not inherited to child processes. */
59 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
60 HANDLE h = (HANDLE) _get_osfhandle (fd);
62 ASSERT (GetHandleInformation (h, &flags));
63 return (flags & HANDLE_FLAG_INHERIT) == 0;
66 ASSERT ((flags = fcntl (fd, F_GETFD)) >= 0);
67 return (flags & FD_CLOEXEC) != 0;
77 for (use_nonblocking = 0; use_nonblocking <= 1; use_nonblocking++)
78 for (use_cloexec = 0; use_cloexec <= !!O_CLOEXEC; use_cloexec++)
85 o_flags |= O_NONBLOCK;
91 ASSERT (pipe2 (fd, o_flags) >= 0);
94 ASSERT (fd[0] != fd[1]);
95 ASSERT (is_open (fd[0]));
96 ASSERT (is_open (fd[1]));
99 ASSERT (is_cloexec (fd[0]));
100 ASSERT (is_cloexec (fd[1]));
104 ASSERT (!is_cloexec (fd[0]));
105 ASSERT (!is_cloexec (fd[1]));
109 ASSERT (get_nonblocking_flag (fd[0]) == 1);
110 ASSERT (get_nonblocking_flag (fd[1]) == 1);
114 ASSERT (get_nonblocking_flag (fd[0]) == 0);
115 ASSERT (get_nonblocking_flag (fd[1]) == 0);
118 ASSERT (close (fd[0]) == 0);
119 ASSERT (close (fd[1]) == 0);