annotate lib/pipe-safer.c @ 40186:8964917f9574

autoupdate
author Karl Berry <karl@freefriends.org>
date Mon, 18 Feb 2019 08:02:49 -0800
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6130
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1 /* Invoke pipe, but avoid some glitches.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2005-2006, 2009-2019 Free Software Foundation, Inc.
6130
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
4 This program is free software: you can redistribute it and/or modify
6130
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
7 (at your option) any later version.
6130
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
8
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
12 GNU General Public License for more details.
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
13
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
6130
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
16
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
17 /* Written by Jim Meyering. */
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
18
7302
8a1a9361108c * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 7125
diff changeset
19 #include <config.h>
6130
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
20
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
21 #include "unistd-safer.h"
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
22
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
23 #include <unistd.h>
7052
9c66c4fabeaf * mkstemp-safer.c [! HAVE_MKSTEMP]: Add prototype for platforms
Eric Blake <ebb9@byu.net>
parents: 6259
diff changeset
24 #include <errno.h>
6130
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
25
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
26 /* Like pipe, but ensure that neither of the file descriptors is
7052
9c66c4fabeaf * mkstemp-safer.c [! HAVE_MKSTEMP]: Add prototype for platforms
Eric Blake <ebb9@byu.net>
parents: 6259
diff changeset
27 STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO. Fail with ENOSYS on
9c66c4fabeaf * mkstemp-safer.c [! HAVE_MKSTEMP]: Add prototype for platforms
Eric Blake <ebb9@byu.net>
parents: 6259
diff changeset
28 platforms that lack pipe. */
6130
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
29
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
30 int
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
31 pipe_safer (int fd[2])
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
32 {
7125
43f38211e7e3 * pipe-safer.c (pipe_safer): Fix misspelling: HAVE_FUNC_PIPE ->
Paul Eggert <eggert@cs.ucla.edu>
parents: 7052
diff changeset
33 #if HAVE_PIPE
43f38211e7e3 * pipe-safer.c (pipe_safer): Fix misspelling: HAVE_FUNC_PIPE ->
Paul Eggert <eggert@cs.ucla.edu>
parents: 7052
diff changeset
34 if (pipe (fd) == 0)
43f38211e7e3 * pipe-safer.c (pipe_safer): Fix misspelling: HAVE_FUNC_PIPE ->
Paul Eggert <eggert@cs.ucla.edu>
parents: 7052
diff changeset
35 {
43f38211e7e3 * pipe-safer.c (pipe_safer): Fix misspelling: HAVE_FUNC_PIPE ->
Paul Eggert <eggert@cs.ucla.edu>
parents: 7052
diff changeset
36 int i;
43f38211e7e3 * pipe-safer.c (pipe_safer): Fix misspelling: HAVE_FUNC_PIPE ->
Paul Eggert <eggert@cs.ucla.edu>
parents: 7052
diff changeset
37 for (i = 0; i < 2; i++)
12394
c30020975750 pipe2-safer: new module
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
38 {
c30020975750 pipe2-safer: new module
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
39 fd[i] = fd_safer (fd[i]);
c30020975750 pipe2-safer: new module
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
40 if (fd[i] < 0)
c30020975750 pipe2-safer: new module
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
41 {
c30020975750 pipe2-safer: new module
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
42 int e = errno;
c30020975750 pipe2-safer: new module
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
43 close (fd[1 - i]);
c30020975750 pipe2-safer: new module
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
44 errno = e;
c30020975750 pipe2-safer: new module
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
45 return -1;
c30020975750 pipe2-safer: new module
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
46 }
c30020975750 pipe2-safer: new module
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
47 }
6130
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
48
7125
43f38211e7e3 * pipe-safer.c (pipe_safer): Fix misspelling: HAVE_FUNC_PIPE ->
Paul Eggert <eggert@cs.ucla.edu>
parents: 7052
diff changeset
49 return 0;
43f38211e7e3 * pipe-safer.c (pipe_safer): Fix misspelling: HAVE_FUNC_PIPE ->
Paul Eggert <eggert@cs.ucla.edu>
parents: 7052
diff changeset
50 }
43f38211e7e3 * pipe-safer.c (pipe_safer): Fix misspelling: HAVE_FUNC_PIPE ->
Paul Eggert <eggert@cs.ucla.edu>
parents: 7052
diff changeset
51 #else
43f38211e7e3 * pipe-safer.c (pipe_safer): Fix misspelling: HAVE_FUNC_PIPE ->
Paul Eggert <eggert@cs.ucla.edu>
parents: 7052
diff changeset
52 errno = ENOSYS;
43f38211e7e3 * pipe-safer.c (pipe_safer): Fix misspelling: HAVE_FUNC_PIPE ->
Paul Eggert <eggert@cs.ucla.edu>
parents: 7052
diff changeset
53 #endif
6130
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
54
7052
9c66c4fabeaf * mkstemp-safer.c [! HAVE_MKSTEMP]: Add prototype for platforms
Eric Blake <ebb9@byu.net>
parents: 6259
diff changeset
55 return -1;
6130
44d5f5bdd253 GNU tar needs these.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
56 }