annotate lib/pipe2-safer.c @ 17160:72f4bab621be

fts: introduce FTS_VERBATIM This gives clients the option to disable stripping of trailing slashes from input path names during fts_open initialization. The recent change v0.0-7611-g3a9002d that made fts_open strip trailing slashes from input path names had a negative impact on findutils that relies on the old fts_open behavior to implement POSIX requirement that each path operand of the find utility shall be evaluated unaltered as it was provided, including all trailing slash characters. * lib/fts_.h (FTS_VERBATIM): New bit flag. (FTS_OPTIONMASK, FTS_NAMEONLY, FTS_STOP): Adjust. * lib/fts.c (fts_open): Honor it.
author Dmitry V. Levin <ldv@altlinux.org>
date Sun, 18 Nov 2012 04:40:18 +0400
parents 8250f2777afc
children e542fd46ad6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12424
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Invoke pipe2, but avoid some glitches.
16201
8250f2777afc maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
2 Copyright (C) 2005-2006, 2009-2012 Free Software Foundation, Inc.
12424
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Eric Blake. */
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 /* Specification. */
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include "unistd-safer.h"
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <unistd.h>
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <errno.h>
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 /* Like pipe2, but ensure that neither of the file descriptors is
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO. */
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 int
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 pipe2_safer (int fd[2], int flags)
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 {
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 /* This is a generalization of the pipe_safer implementation. */
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 if (pipe2 (fd, flags) == 0)
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 {
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 int i;
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 for (i = 0; i < 2; i++)
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 {
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 fd[i] = fd_safer_flag (fd[i], flags);
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 if (fd[i] < 0)
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 {
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 int e = errno;
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 close (fd[1 - i]);
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 errno = e;
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 return -1;
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 }
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 }
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 return 0;
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 }
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 return -1;
b754d05eae53 Move pipe2-safer code to its own file.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 }