2 Copyright (C) 2009-2021 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, see <https://www.gnu.org/licenses/>. */
21 #include "signature.h"
22 SIGNATURE_CHECK (pipe, int, (int[2]));
27 #if defined _WIN32 && ! defined __CYGWIN__
28 /* Get declarations of the native Windows API functions. */
29 # define WIN32_LEAN_AND_MEAN
31 /* Get _get_osfhandle. */
32 # if GNULIB_MSVC_NOTHROW
33 # include "msvc-nothrow.h"
39 #include "binary-io.h"
42 /* Return true if FD is open. */
46 #if defined _WIN32 && ! defined __CYGWIN__
47 /* On native Windows, the initial state of unassigned standard file
48 descriptors is that they are open but point to an
49 INVALID_HANDLE_VALUE, and there is no fcntl. */
50 return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE;
53 # error Please port fcntl to your platform
55 return 0 <= fcntl (fd, F_GETFL);
59 /* Return true if FD is not inherited to child processes. */
63 #if defined _WIN32 && ! defined __CYGWIN__
64 HANDLE h = (HANDLE) _get_osfhandle (fd);
66 ASSERT (GetHandleInformation (h, &flags));
67 return (flags & HANDLE_FLAG_INHERIT) == 0;
70 ASSERT ((flags = fcntl (fd, F_GETFD)) >= 0);
71 return (flags & FD_CLOEXEC) != 0;
75 /* Return true if FD is in non-blocking mode. */
77 is_nonblocking (int fd)
79 #if defined _WIN32 && ! defined __CYGWIN__
80 /* We don't use the non-blocking mode for sockets here. */
84 ASSERT ((flags = fcntl (fd, F_GETFL)) >= 0);
85 return (flags & O_NONBLOCK) != 0;
96 ASSERT (pipe (fd) >= 0);
99 ASSERT (fd[0] != fd[1]);
100 ASSERT (is_open (fd[0]));
101 ASSERT (is_open (fd[1]));
102 ASSERT (!is_cloexec (fd[0]));
103 ASSERT (!is_cloexec (fd[1]));
104 ASSERT (!is_nonblocking (fd[0]));
105 ASSERT (!is_nonblocking (fd[1]));