Mercurial > hg > octave-jordi > gnulib-hg
annotate lib/pipe-safer.c @ 18079:4c948fd76734 default tip master
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Mon, 24 Aug 2015 06:09:19 -0700 |
parents | ab58d4870664 |
children |
rev | line source |
---|---|
6130 | 1 /* Invoke pipe, but avoid some glitches. |
17848 | 2 Copyright (C) 2005-2006, 2009-2015 Free Software Foundation, Inc. |
6130 | 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 | 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 | 8 |
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. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
6130 | 16 |
17 /* Written by Jim Meyering. */ | |
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 | 20 |
21 #include "unistd-safer.h" | |
22 | |
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 | 25 |
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 | 29 |
30 int | |
31 pipe_safer (int fd[2]) | |
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 | 38 { |
39 fd[i] = fd_safer (fd[i]); | |
40 if (fd[i] < 0) | |
41 { | |
42 int e = errno; | |
43 close (fd[1 - i]); | |
44 errno = e; | |
45 return -1; | |
46 } | |
47 } | |
6130 | 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 | 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 | 56 } |