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 (pipe, int, (int[2]));
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"
37 /* Return true if FD is open. */
41 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
42 /* On Win32, the initial state of unassigned standard file
43 descriptors is that they are open but point to an
44 INVALID_HANDLE_VALUE, and there is no fcntl. */
45 return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE;
48 # error Please port fcntl to your platform
50 return 0 <= fcntl (fd, F_GETFL);
54 /* Return true if FD is not inherited to child processes. */
58 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
59 HANDLE h = (HANDLE) _get_osfhandle (fd);
61 ASSERT (GetHandleInformation (h, &flags));
62 return (flags & HANDLE_FLAG_INHERIT) == 0;
65 ASSERT ((flags = fcntl (fd, F_GETFD)) >= 0);
66 return (flags & FD_CLOEXEC) != 0;
70 /* Return true if FD is in non-blocking mode. */
72 is_nonblocking (int fd)
74 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
75 /* We don't use the non-blocking mode for sockets here. */
79 ASSERT ((flags = fcntl (fd, F_GETFL)) >= 0);
80 return (flags & O_NONBLOCK) != 0;
91 ASSERT (pipe (fd) >= 0);
94 ASSERT (fd[0] != fd[1]);
95 ASSERT (is_open (fd[0]));
96 ASSERT (is_open (fd[1]));
97 ASSERT (!is_cloexec (fd[0]));
98 ASSERT (!is_cloexec (fd[1]));
99 ASSERT (!is_nonblocking (fd[0]));
100 ASSERT (!is_nonblocking (fd[1]));