annotate lib/pipe.c @ 40057:b06060465f09

maint: Run 'make update-copyright'
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 01 Jan 2019 00:25:11 +0100
parents beb2ad957aca
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13925
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Create a pipe.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19595
diff changeset
2 Copyright (C) 2009-2019 Free Software Foundation, Inc.
13925
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 any later version.
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License along
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 with this program; if not, see <https://www.gnu.org/licenses/>. */
13925
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #include <config.h>
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 /* Specification. */
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #include <unistd.h>
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
19595
beb2ad957aca Simplify code. Drop support for Borland C++ on Windows.
Bruno Haible <bruno@clisp.org>
parents: 19484
diff changeset
22 #if defined _WIN32 && ! defined __CYGWIN__
16242
59c686e5b2df Talk about "native Windows API", not "Woe32".
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
23 /* Native Windows API. */
13925
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 /* Get _pipe(). */
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 # include <io.h>
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 /* Get _O_BINARY. */
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 # include <fcntl.h>
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 int
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 pipe (int fd[2])
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 {
15326
52719068f9c2 pipe, pipe2: don't corrupt fd on error
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
34 /* Mingw changes fd to {-1,-1} on failure, but this violates
52719068f9c2 pipe, pipe2: don't corrupt fd on error
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
35 http://austingroupbugs.net/view.php?id=467 */
52719068f9c2 pipe, pipe2: don't corrupt fd on error
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
36 int tmp[2];
52719068f9c2 pipe, pipe2: don't corrupt fd on error
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
37 int result = _pipe (tmp, 4096, _O_BINARY);
52719068f9c2 pipe, pipe2: don't corrupt fd on error
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
38 if (!result)
52719068f9c2 pipe, pipe2: don't corrupt fd on error
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
39 {
52719068f9c2 pipe, pipe2: don't corrupt fd on error
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
40 fd[0] = tmp[0];
52719068f9c2 pipe, pipe2: don't corrupt fd on error
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
41 fd[1] = tmp[1];
52719068f9c2 pipe, pipe2: don't corrupt fd on error
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
42 }
52719068f9c2 pipe, pipe2: don't corrupt fd on error
Eric Blake <eblake@redhat.com>
parents: 14079
diff changeset
43 return result;
13925
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 }
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 #else
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 # error "This platform lacks a pipe function, and Gnulib doesn't provide a replacement. This is a bug in Gnulib."
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49
29a686188651 pipe-posix: Make it work in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 #endif