Mercurial > hg > octave-lojdl > gnulib-hg
annotate lib/fts_.h @ 17464:290d581e2e24
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Sat, 10 Aug 2013 07:10:55 -0700 |
parents | e542fd46ad6f |
children |
rev | line source |
---|---|
5858 | 1 /* Traverse a file hierarchy. |
2 | |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
17160
diff
changeset
|
3 Copyright (C) 2004-2013 Free Software Foundation, Inc. |
5858 | 4 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7797
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
5858 | 6 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:
7797
diff
changeset
|
7 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:
7797
diff
changeset
|
8 (at your option) any later version. |
5858 | 9 |
10 This program 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 | |
13 GNU General Public License for more details. | |
14 | |
15 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:
7797
diff
changeset
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
5858 | 17 |
18 /* | |
19 * Copyright (c) 1989, 1993 | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
20 * The Regents of the University of California. All rights reserved. |
5858 | 21 * |
22 * Redistribution and use in source and binary forms, with or without | |
23 * modification, are permitted provided that the following conditions | |
24 * are met: | |
25 * 1. Redistributions of source code must retain the above copyright | |
26 * notice, this list of conditions and the following disclaimer. | |
27 * 2. Redistributions in binary form must reproduce the above copyright | |
28 * notice, this list of conditions and the following disclaimer in the | |
29 * documentation and/or other materials provided with the distribution. | |
30 * 4. Neither the name of the University nor the names of its contributors | |
31 * may be used to endorse or promote products derived from this software | |
32 * without specific prior written permission. | |
33 * | |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
34 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND |
5858 | 35 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
36 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
37 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
38 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
39 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
40 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
42 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
43 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
44 * SUCH DAMAGE. | |
45 * | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
46 * @(#)fts.h 8.3 (Berkeley) 8/14/94 |
5858 | 47 */ |
48 | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
49 #ifndef _FTS_H |
5858 | 50 # define _FTS_H 1 |
51 | |
52 # ifdef _LIBC | |
53 # include <features.h> | |
54 # else | |
55 # undef __THROW | |
56 # define __THROW | |
57 # undef __BEGIN_DECLS | |
58 # undef __END_DECLS | |
13564
1b02c6324dca
fts: allow compilation with C++
Giuseppe Scrivano <gscrivano@gnu.org>
parents:
13091
diff
changeset
|
59 # ifdef __cplusplus |
1b02c6324dca
fts: allow compilation with C++
Giuseppe Scrivano <gscrivano@gnu.org>
parents:
13091
diff
changeset
|
60 # define __BEGIN_DECLS extern "C" { |
1b02c6324dca
fts: allow compilation with C++
Giuseppe Scrivano <gscrivano@gnu.org>
parents:
13091
diff
changeset
|
61 # define __END_DECLS } |
1b02c6324dca
fts: allow compilation with C++
Giuseppe Scrivano <gscrivano@gnu.org>
parents:
13091
diff
changeset
|
62 # else |
1b02c6324dca
fts: allow compilation with C++
Giuseppe Scrivano <gscrivano@gnu.org>
parents:
13091
diff
changeset
|
63 # define __BEGIN_DECLS |
1b02c6324dca
fts: allow compilation with C++
Giuseppe Scrivano <gscrivano@gnu.org>
parents:
13091
diff
changeset
|
64 # define __END_DECLS |
1b02c6324dca
fts: allow compilation with C++
Giuseppe Scrivano <gscrivano@gnu.org>
parents:
13091
diff
changeset
|
65 # endif |
5858 | 66 # endif |
67 | |
68 # include <stddef.h> | |
69 # include <sys/types.h> | |
15529
894e5e6ae541
fts: add/use new struct member, fts_dirp
Jim Meyering <meyering@redhat.com>
parents:
15374
diff
changeset
|
70 # include <dirent.h> |
5867
67b499052f7f
* fts.c: Include fts_.h first, to check interface.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5858
diff
changeset
|
71 # include <sys/stat.h> |
7639
1670d42131d7
Make fts (in FTS_CWDFD mode) more efficient by caching a few open
Jim Meyering <jim@meyering.net>
parents:
7482
diff
changeset
|
72 # include "i-ring.h" |
5858 | 73 |
74 typedef struct { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
75 struct _ftsent *fts_cur; /* current node */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
76 struct _ftsent *fts_child; /* linked list of children */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
77 struct _ftsent **fts_array; /* sort array */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
78 dev_t fts_dev; /* starting device # */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
79 char *fts_path; /* file name for this descent */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
80 int fts_rfd; /* fd for root */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
81 int fts_cwd_fd; /* the file descriptor on which the |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
82 virtual cwd is open, or AT_FDCWD */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
83 size_t fts_pathlen; /* sizeof(path) */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
84 size_t fts_nitems; /* elements in the sort array */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
85 int (*fts_compar) (struct _ftsent const **, struct _ftsent const **); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
86 /* compare fn */ |
5858 | 87 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
88 # define FTS_COMFOLLOW 0x0001 /* follow command line symlinks */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
89 # define FTS_LOGICAL 0x0002 /* logical walk */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
90 # define FTS_NOCHDIR 0x0004 /* don't change directories */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
91 # define FTS_NOSTAT 0x0008 /* don't get stat info */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
92 # define FTS_PHYSICAL 0x0010 /* physical walk */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
93 # define FTS_SEEDOT 0x0020 /* return dot and dot-dot */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
94 # define FTS_XDEV 0x0040 /* don't cross devices */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
95 # define FTS_WHITEOUT 0x0080 /* return whiteout information */ |
5858 | 96 |
97 /* There are two ways to detect cycles. | |
6035
a166800910b5
Mention that with FTS_LOGICAL, we use FTS_TIGHT_CYCLE_CHECK.
Jim Meyering <jim@meyering.net>
parents:
5907
diff
changeset
|
98 The lazy way (which works only with FTS_PHYSICAL), |
a166800910b5
Mention that with FTS_LOGICAL, we use FTS_TIGHT_CYCLE_CHECK.
Jim Meyering <jim@meyering.net>
parents:
5907
diff
changeset
|
99 with which one may process a directory that is a |
5858 | 100 part of the cycle several times before detecting the cycle. |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
101 The "tight" way, whereby fts uses more memory (proportional |
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
102 to number of "active" directories, aka distance from root |
5858 | 103 of current tree to current directory -- see active_dir_ht) |
104 to detect any cycle right away. For example, du must use | |
105 this option to avoid counting disk space in a cycle multiple | |
106 times, but chown -R need not. | |
6035
a166800910b5
Mention that with FTS_LOGICAL, we use FTS_TIGHT_CYCLE_CHECK.
Jim Meyering <jim@meyering.net>
parents:
5907
diff
changeset
|
107 The default is to use the constant-memory lazy way, when possible |
a166800910b5
Mention that with FTS_LOGICAL, we use FTS_TIGHT_CYCLE_CHECK.
Jim Meyering <jim@meyering.net>
parents:
5907
diff
changeset
|
108 (see below). |
a166800910b5
Mention that with FTS_LOGICAL, we use FTS_TIGHT_CYCLE_CHECK.
Jim Meyering <jim@meyering.net>
parents:
5907
diff
changeset
|
109 |
a166800910b5
Mention that with FTS_LOGICAL, we use FTS_TIGHT_CYCLE_CHECK.
Jim Meyering <jim@meyering.net>
parents:
5907
diff
changeset
|
110 However, with FTS_LOGICAL (when following symlinks, e.g., chown -L) |
a166800910b5
Mention that with FTS_LOGICAL, we use FTS_TIGHT_CYCLE_CHECK.
Jim Meyering <jim@meyering.net>
parents:
5907
diff
changeset
|
111 using lazy cycle detection is inadequate. For example, traversing |
a166800910b5
Mention that with FTS_LOGICAL, we use FTS_TIGHT_CYCLE_CHECK.
Jim Meyering <jim@meyering.net>
parents:
5907
diff
changeset
|
112 a directory containing a symbolic link to a peer directory, it is |
a166800910b5
Mention that with FTS_LOGICAL, we use FTS_TIGHT_CYCLE_CHECK.
Jim Meyering <jim@meyering.net>
parents:
5907
diff
changeset
|
113 possible to encounter the same directory twice even though there |
a166800910b5
Mention that with FTS_LOGICAL, we use FTS_TIGHT_CYCLE_CHECK.
Jim Meyering <jim@meyering.net>
parents:
5907
diff
changeset
|
114 is no cycle: |
a166800910b5
Mention that with FTS_LOGICAL, we use FTS_TIGHT_CYCLE_CHECK.
Jim Meyering <jim@meyering.net>
parents:
5907
diff
changeset
|
115 dir |
a166800910b5
Mention that with FTS_LOGICAL, we use FTS_TIGHT_CYCLE_CHECK.
Jim Meyering <jim@meyering.net>
parents:
5907
diff
changeset
|
116 ... |
a166800910b5
Mention that with FTS_LOGICAL, we use FTS_TIGHT_CYCLE_CHECK.
Jim Meyering <jim@meyering.net>
parents:
5907
diff
changeset
|
117 slink -> dir |
a166800910b5
Mention that with FTS_LOGICAL, we use FTS_TIGHT_CYCLE_CHECK.
Jim Meyering <jim@meyering.net>
parents:
5907
diff
changeset
|
118 So, when FTS_LOGICAL is selected, we have to use a different |
a166800910b5
Mention that with FTS_LOGICAL, we use FTS_TIGHT_CYCLE_CHECK.
Jim Meyering <jim@meyering.net>
parents:
5907
diff
changeset
|
119 mode of cycle detection: FTS_TIGHT_CYCLE_CHECK. */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
120 # define FTS_TIGHT_CYCLE_CHECK 0x0100 |
5858 | 121 |
7151 | 122 /* Use this flag to enable semantics with which the parent |
123 application may be made both more efficient and more robust. | |
124 Whereas the default is to visit each directory in a recursive | |
125 traversal (via chdir), using this flag makes it so the initial | |
126 working directory is never changed. Instead, these functions | |
127 perform the traversal via a virtual working directory, maintained | |
128 through the file descriptor member, fts_cwd_fd. */ | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
129 # define FTS_CWDFD 0x0200 |
7151 | 130 |
7482
26914593f079
Big performance improvement for fts-based tools that use FTS_NOSTAT.
Jim Meyering <jim@meyering.net>
parents:
7151
diff
changeset
|
131 /* Historically, for each directory that fts initially encounters, it would |
26914593f079
Big performance improvement for fts-based tools that use FTS_NOSTAT.
Jim Meyering <jim@meyering.net>
parents:
7151
diff
changeset
|
132 open it, read all entries, and stat each entry, storing the results, and |
26914593f079
Big performance improvement for fts-based tools that use FTS_NOSTAT.
Jim Meyering <jim@meyering.net>
parents:
7151
diff
changeset
|
133 then it would process the first entry. But that behavior is bad for |
26914593f079
Big performance improvement for fts-based tools that use FTS_NOSTAT.
Jim Meyering <jim@meyering.net>
parents:
7151
diff
changeset
|
134 locality of reference, and also causes trouble with inode-simulating |
26914593f079
Big performance improvement for fts-based tools that use FTS_NOSTAT.
Jim Meyering <jim@meyering.net>
parents:
7151
diff
changeset
|
135 file systems like FAT, CIFS, FUSE-based ones, etc., when entries from |
26914593f079
Big performance improvement for fts-based tools that use FTS_NOSTAT.
Jim Meyering <jim@meyering.net>
parents:
7151
diff
changeset
|
136 their name/inode cache are flushed too early. |
26914593f079
Big performance improvement for fts-based tools that use FTS_NOSTAT.
Jim Meyering <jim@meyering.net>
parents:
7151
diff
changeset
|
137 Use this flag to make fts_open and fts_read defer the stat/lstat/fststat |
10317
cf86778a4e1a
* lib/fts_.h: Fix grammar (insert a missing "is") in a comment.
Jim Meyering <meyering@redhat.com>
parents:
9309
diff
changeset
|
138 of each entry until it is actually processed. However, note that if you |
cf86778a4e1a
* lib/fts_.h: Fix grammar (insert a missing "is") in a comment.
Jim Meyering <meyering@redhat.com>
parents:
9309
diff
changeset
|
139 use this option and also specify a comparison function, that function may |
10843
36479bd141ee
fts: provide dirent.d_type via FTSENT.fts_statp, when possible
Jim Meyering <meyering@redhat.com>
parents:
10317
diff
changeset
|
140 not examine any data via fts_statp. However, when fts_statp->st_mode is |
36479bd141ee
fts: provide dirent.d_type via FTSENT.fts_statp, when possible
Jim Meyering <meyering@redhat.com>
parents:
10317
diff
changeset
|
141 nonzero, the S_IFMT type bits are valid, with mapped dirent.d_type data. |
36479bd141ee
fts: provide dirent.d_type via FTSENT.fts_statp, when possible
Jim Meyering <meyering@redhat.com>
parents:
10317
diff
changeset
|
142 Of course, that happens only on file systems that provide useful |
36479bd141ee
fts: provide dirent.d_type via FTSENT.fts_statp, when possible
Jim Meyering <meyering@redhat.com>
parents:
10317
diff
changeset
|
143 dirent.d_type data. */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
144 # define FTS_DEFER_STAT 0x0400 |
7482
26914593f079
Big performance improvement for fts-based tools that use FTS_NOSTAT.
Jim Meyering <jim@meyering.net>
parents:
7151
diff
changeset
|
145 |
15374
04a9f678e342
fts: introduce FTS_NOATIME
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
146 # define FTS_NOATIME 0x0800 /* use O_NOATIME during traversal */ |
04a9f678e342
fts: introduce FTS_NOATIME
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
147 |
17160
72f4bab621be
fts: introduce FTS_VERBATIM
Dmitry V. Levin <ldv@altlinux.org>
parents:
16235
diff
changeset
|
148 /* Use this flag to disable stripping of trailing slashes |
72f4bab621be
fts: introduce FTS_VERBATIM
Dmitry V. Levin <ldv@altlinux.org>
parents:
16235
diff
changeset
|
149 from input path names during fts_open initialization. */ |
72f4bab621be
fts: introduce FTS_VERBATIM
Dmitry V. Levin <ldv@altlinux.org>
parents:
16235
diff
changeset
|
150 # define FTS_VERBATIM 0x1000 |
5858 | 151 |
17160
72f4bab621be
fts: introduce FTS_VERBATIM
Dmitry V. Levin <ldv@altlinux.org>
parents:
16235
diff
changeset
|
152 # define FTS_OPTIONMASK 0x1fff /* valid user option mask */ |
72f4bab621be
fts: introduce FTS_VERBATIM
Dmitry V. Levin <ldv@altlinux.org>
parents:
16235
diff
changeset
|
153 |
72f4bab621be
fts: introduce FTS_VERBATIM
Dmitry V. Levin <ldv@altlinux.org>
parents:
16235
diff
changeset
|
154 # define FTS_NAMEONLY 0x2000 /* (private) child names only */ |
72f4bab621be
fts: introduce FTS_VERBATIM
Dmitry V. Levin <ldv@altlinux.org>
parents:
16235
diff
changeset
|
155 # define FTS_STOP 0x4000 /* (private) unrecoverable error */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
156 int fts_options; /* fts_open options, global flags */ |
5858 | 157 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
158 /* Map a directory's device number to a boolean. The boolean is |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
159 true if for that file system (type determined by a single fstatfs |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
160 call per FS) st_nlink can be used to calculate the number of |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
161 sub-directory entries in a directory. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
162 Using this table is an optimization that permits us to look up |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
163 file system type on a per-inode basis at the minimal cost of |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
164 calling fstatfs only once per traversed device. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
165 struct hash_table *fts_leaf_optimization_works_ht; |
11164
90715da41753
fts: arrange not to stat non-directories in more cases
Jim Meyering <meyering@redhat.com>
parents:
10843
diff
changeset
|
166 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
167 union { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
168 /* This data structure is used if FTS_TIGHT_CYCLE_CHECK is |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
169 specified. It records the directories between a starting |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
170 point and the current directory. I.e., a directory is |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
171 recorded here IFF we have visited it once, but we have not |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
172 yet completed processing of all its entries. Every time we |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
173 visit a new directory, we add that directory to this set. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
174 When we finish with a directory (usually by visiting it a |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
175 second time), we remove it from this set. Each entry in |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
176 this data structure is a device/inode pair. This data |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
177 structure is used to detect directory cycles efficiently and |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
178 promptly even when the depth of a hierarchy is in the tens |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
179 of thousands. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
180 struct hash_table *ht; |
5872 | 181 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
182 /* FIXME: rename these two members to have the fts_ prefix */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
183 /* This data structure uses a lazy cycle-detection algorithm, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
184 as done by rm via cycle-check.c. It's the default, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
185 but it's not appropriate for programs like du. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
186 struct cycle_check_state *state; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
187 } fts_cycle; |
7639
1670d42131d7
Make fts (in FTS_CWDFD mode) more efficient by caching a few open
Jim Meyering <jim@meyering.net>
parents:
7482
diff
changeset
|
188 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
189 /* A stack of the file descriptors corresponding to the |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
190 most-recently traversed parent directories. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
191 Currently used only in FTS_CWDFD mode. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
192 I_ring fts_fd_ring; |
5858 | 193 } FTS; |
194 | |
195 typedef struct _ftsent { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
196 struct _ftsent *fts_cycle; /* cycle node */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
197 struct _ftsent *fts_parent; /* parent directory */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
198 struct _ftsent *fts_link; /* next file in directory */ |
15529
894e5e6ae541
fts: add/use new struct member, fts_dirp
Jim Meyering <meyering@redhat.com>
parents:
15374
diff
changeset
|
199 DIR *fts_dirp; /* Dir pointer for any directory |
894e5e6ae541
fts: add/use new struct member, fts_dirp
Jim Meyering <meyering@redhat.com>
parents:
15374
diff
changeset
|
200 containing more entries than we |
894e5e6ae541
fts: add/use new struct member, fts_dirp
Jim Meyering <meyering@redhat.com>
parents:
15374
diff
changeset
|
201 read at one time. */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
202 long fts_number; /* local numeric value */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
203 void *fts_pointer; /* local address value */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
204 char *fts_accpath; /* access file name */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
205 char *fts_path; /* root name; == fts_fts->fts_path */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
206 int fts_errno; /* errno for this node */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
207 int fts_symfd; /* fd for symlink */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
208 size_t fts_pathlen; /* strlen(fts_path) */ |
5858 | 209 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
210 FTS *fts_fts; /* the file hierarchy itself */ |
5858 | 211 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
212 # define FTS_ROOTPARENTLEVEL (-1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
213 # define FTS_ROOTLEVEL 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
214 ptrdiff_t fts_level; /* depth (-1 to N) */ |
5858 | 215 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
216 size_t fts_namelen; /* strlen(fts_name) */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
217 nlink_t fts_n_dirs_remaining; /* count down from st_nlink */ |
5858 | 218 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
219 # define FTS_D 1 /* preorder directory */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
220 # define FTS_DC 2 /* directory that causes cycles */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
221 # define FTS_DEFAULT 3 /* none of the above */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
222 # define FTS_DNR 4 /* unreadable directory */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
223 # define FTS_DOT 5 /* dot or dot-dot */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
224 # define FTS_DP 6 /* postorder directory */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
225 # define FTS_ERR 7 /* error; errno is set */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
226 # define FTS_F 8 /* regular file */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
227 # define FTS_INIT 9 /* initialized only */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
228 # define FTS_NS 10 /* stat(2) failed */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
229 # define FTS_NSOK 11 /* no stat(2) requested */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
230 # define FTS_SL 12 /* symbolic link */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
231 # define FTS_SLNONE 13 /* symbolic link without target */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
232 # define FTS_W 14 /* whiteout object */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
233 unsigned short int fts_info; /* user flags for FTSENT structure */ |
5858 | 234 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
235 # define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
236 # define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
237 unsigned short int fts_flags; /* private flags for FTSENT structure */ |
5858 | 238 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
239 # define FTS_AGAIN 1 /* read node again */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
240 # define FTS_FOLLOW 2 /* follow symbolic link */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
241 # define FTS_NOINSTR 3 /* no instructions */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
242 # define FTS_SKIP 4 /* discard node */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
243 unsigned short int fts_instr; /* fts_set() instructions */ |
5858 | 244 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
245 struct stat fts_statp[1]; /* stat(2) information */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
246 char fts_name[1]; /* file name */ |
5858 | 247 } FTSENT; |
248 | |
11925
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
249 #ifndef __GNUC_PREREQ |
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
250 # if defined __GNUC__ && defined __GNUC_MINOR__ |
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
251 # define __GNUC_PREREQ(maj, min) \ |
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
252 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) |
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
253 # else |
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
254 # define __GNUC_PREREQ(maj, min) 0 |
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
255 # endif |
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
256 #endif |
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
257 |
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
258 #if __GNUC_PREREQ (3,4) |
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
259 # undef __attribute_warn_unused_result__ |
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
260 # define __attribute_warn_unused_result__ \ |
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
261 __attribute__ ((__warn_unused_result__)) |
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
262 #else |
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
263 # define __attribute_warn_unused_result__ /* empty */ |
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
264 #endif |
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
265 |
5858 | 266 __BEGIN_DECLS |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
267 FTSENT *fts_children (FTS *, int) __THROW __attribute_warn_unused_result__; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
268 int fts_close (FTS *) __THROW __attribute_warn_unused_result__; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
269 FTS *fts_open (char * const *, int, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
270 int (*)(const FTSENT **, const FTSENT **)) |
11925
4934b28baa2b
fts: help ensure that return values are not ignored
Jim Meyering <meyering@redhat.com>
parents:
11164
diff
changeset
|
271 __THROW __attribute_warn_unused_result__; |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
272 FTSENT *fts_read (FTS *) __THROW __attribute_warn_unused_result__; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11925
diff
changeset
|
273 int fts_set (FTS *, FTSENT *, int) __THROW; |
5858 | 274 __END_DECLS |
275 | |
276 #endif /* fts.h */ |