1 /* Copyright (C) 1992-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
20 #include <sys/socket.h>
24 #include <fcntl-internal.h>
27 /* Create a one-way communication channel (pipe).
28 Actually the channel is two-way on the Hurd.
29 If successful, two file descriptors are stored in FDS;
30 bytes written on FDS[1] can be read from FDS[0].
31 Apply FLAGS to the new file descriptors.
32 Returns 0 if successful, -1 if not. */
34 __pipe2 (int fds
[2], int flags
)
36 int save_errno
= errno
;
39 if (flags
& ~(O_CLOEXEC
| O_NONBLOCK
))
40 return __hurd_fail (EINVAL
);
42 flags
= o_to_sock_flags (flags
);
44 /* The magic S_IFIFO protocol tells the pflocal server to create
45 sockets which report themselves as FIFOs, as POSIX requires for
47 result
= __socketpair (PF_LOCAL
, SOCK_STREAM
| flags
, S_IFIFO
, fds
);
48 if (result
== -1 && errno
== EPROTONOSUPPORT
)
50 /* We contacted an "old" pflocal server that doesn't support the
51 magic S_IFIFO protocol.
52 FIXME: Remove this junk somewhere in the future. */
53 __set_errno (save_errno
);
54 return __socketpair (PF_LOCAL
, SOCK_STREAM
| flags
, 0, fds
);
59 weak_alias (__pipe2
, pipe2
)