]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/mach/hurd/pipe2.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / sysdeps / mach / hurd / pipe2.c
CommitLineData
04277e02 1/* Copyright (C) 1992-2019 Free Software Foundation, Inc.
de195be0
TS
2
3 This file is part of the GNU C Library.
4
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.
9
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.
14
15 You should have received a copy of the GNU Lesser General Public
38547460 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
de195be0
TS
18
19#include <errno.h>
20#include <sys/socket.h>
21#include <sys/stat.h>
22#include <unistd.h>
23#include <fcntl.h>
24#include <fcntl-internal.h>
25#include <hurd.h>
26
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. */
33int
34__pipe2 (int fds[2], int flags)
35{
36 int save_errno = errno;
37 int result;
38
39 if (flags & ~(O_CLOEXEC | O_NONBLOCK))
40 return __hurd_fail (EINVAL);
41
42 flags = o_to_sock_flags (flags);
43
44 /* The magic S_IFIFO protocol tells the pflocal server to create
45 sockets which report themselves as FIFOs, as POSIX requires for
46 pipes. */
47 result = __socketpair (PF_LOCAL, SOCK_STREAM | flags, S_IFIFO, fds);
48 if (result == -1 && errno == EPROTONOSUPPORT)
49 {
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);
55 }
56
57 return result;
58}
59weak_alias (__pipe2, pipe2)