OSDN Git Service

(split) LDP v3.30, v3.31 の定型的な変更内容を反映。
[linuxjm/LDP_man-pages.git] / draft / man3 / ftw.3
1 .\" Copyright (c) 1993 Michael Haardt (u31b3hs@pool.informatik.rwth-aachen.de)
2 .\" and copyright (c) 1999 Andries Brouwer (aeb@cwi.nl)
3 .\" and copyright (c) 2006 Justin Pryzby <justinpryzby@users.sf.net>
4 .\" and copyright (c) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\"
6 .\" This is free documentation; you can redistribute it and/or
7 .\" modify it under the terms of the GNU General Public License as
8 .\" published by the Free Software Foundation; either version 2 of
9 .\" the License, or (at your option) any later version.
10 .\"
11 .\" The GNU General Public License's references to "object code"
12 .\" and "executables" are to be interpreted as the output of any
13 .\" document formatting or typesetting system, including
14 .\" intermediate and printed output.
15 .\"
16 .\" This manual is distributed in the hope that it will be useful,
17 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
18 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 .\" GNU General Public License for more details.
20 .\"
21 .\" You should have received a copy of the GNU General Public
22 .\" License along with this manual; if not, write to the Free
23 .\" Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
24 .\" USA.
25 .\"
26 .\" Modified Sun Jul 25 11:02:22 1993 by Rik Faith (faith@cs.unc.edu)
27 .\" 2006-05-24, Justin Pryzby <justinpryzby@users.sf.net>
28 .\"     document FTW_ACTIONRETVAL; include .SH "RETURN VALUE";
29 .\" 2006-05-24, Justin Pryzby <justinpryzby@users.sf.net> and
30 .\"     Michael Kerrisk <mtk.manpages@gmail.com>
31 .\"     reorganized and rewrote much of the page
32 .\" 2006-05-24, Michael Kerrisk <mtk.manpages@gmail.com>
33 .\"     Added an example program.
34 .\"
35 .\" Japanese Version Copyright (c) 1998 NAKANO Takeo all rights reserved.
36 .\" Translated 1998-04-28, NAKANO Takeo <nakano@apm.seikei.ac.jp>
37 .\" Updated & Modified 1999-09-14, NAKANO Takeo <nakano@apm.seikei.ac.jp>
38 .\" Updated & Modified 2005-11-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
39 .\" Updated 2006-07-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.36
40 .\"
41 .\" WORD:       file descriptor         ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼
42 .\"
43 .TH FTW 3 2010-09-20 "Linux" "Linux Programmer's Manual"
44 .\"O .SH NAME
45 .SH Ì¾Á°
46 .\"O ftw, nftw \- file tree walk
47 ftw, nftw \- ¥Õ¥¡¥¤¥ë¥Ä¥ê¡¼¤òÊ⤭¤Þ¤ï¤ë
48 .\"O .SH SYNOPSIS
49 .SH ½ñ¼°
50 .nf
51 .B #include <ftw.h>
52 .sp
53 .BI "int ftw(const char *" dirpath ,
54 .BI "        int (*" fn ") (const char *" fpath ", const struct stat *" sb ,
55 .BI "                   int " typeflag ),
56 .BI "        int " nopenfd );
57 .sp
58 .\"O+ .BR "#define _XOPEN_SOURCE 500" "   /* See feature_test_macros(7) */"
59 .BR "#define _XOPEN_SOURCE 500" "   /* feature_test_macros(7) »²¾È */"
60 .B #define _XOPEN_SOURCE 500
61 .B #include <ftw.h>
62 .sp
63 .BI "int nftw(const char *" dirpath ,
64 .BI "        int (*" fn ") (const char *" fpath ", const struct stat *" sb ,
65 .BI "                   int " typeflag ", struct FTW *" ftwbuf ),
66 .BI "        int " nopenfd ", int " flags );
67 .fi
68 .\"O .SH DESCRIPTION
69 .SH ÀâÌÀ
70 .\"O .BR ftw ()
71 .\"O walks through the directory tree that is
72 .\"O located under the directory \fIdirpath\fP,
73 .\"O and calls \fIfn\fP() once for each entry in the tree.
74 .\"O By default, directories are handled before the files and
75 .\"O subdirectories they contain (preorder traversal).
76 .BR ftw ()
77 ¤Ï¡¢
78 .I dirpath
79 ¤Ç»ØÄꤵ¤ì¤¿¥Ç¥£¥ì¥¯¥È¥ê°Ê²¼¤Î¥Ç¥£¥ì¥¯¥È¥ê¥Ä¥ê¡¼Á´ÂΤòÊ⤭¤Þ¤ï¤ê¡¢
80 ¥Ä¥ê¡¼Ãæ¤Ç¥¨¥ó¥È¥ê¤¬¸«ÉÕ¤«¤ë¤´¤È¤Ë¡¢
81 .IR fn ()
82 ¤ò¸Æ¤Ó½Ð¤¹¡£
83 ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢¥Ç¥£¥ì¥¯¥È¥ê¤½¤Î¤â¤Î¤¬¡¢¤½¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ë¤¢¤ë¥Õ¥¡¥¤¥ë¤ä
84 ¥µ¥Ö¥Ç¥£¥ì¥¯¥È¥ê¤è¤ê¤âÀè¤Ë½èÍý¤µ¤ì¤ë (¹Ô¤­¤¬¤±½çõº÷; preorder traversal)¡£
85
86 .\"O To avoid using up all of the calling process's file descriptors,
87 .\"O \fInopenfd\fP specifies the maximum number of directories that
88 .\"O .BR ftw ()
89 .\"O will hold open simultaneously.
90 .\"O When
91 .\"O the search depth exceeds this,
92 .\"O .BR ftw ()
93 .\"O will become slower because
94 .\"O directories have to be closed and reopened.
95 .\"O .BR ftw ()
96 .\"O uses at most
97 .\"O one file descriptor for each level in the directory tree.
98 ¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤¬ÍøÍѲÄǽ¤Ê¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ò»È¤¤ÀڤäÆ
99 ¤·¤Þ¤ï¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¤¿¤á¡¢
100 .BR ftw ()
101 ¤¬Æ±»þ¤Ë¥ª¡¼¥×¥ó¤¹¤ë¥Ç¥£¥ì¥¯¥È¥ê¤ÎºÇÂç¿ô¤ò
102 .I nopenfd
103 ¤Ç»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
104 õº÷¤Î¿¼¤µ¤¬¤³¤ÎÃͤò±Û¤¨¤ë¤È¡¢
105 °ì¤Ä¤Î¥Ç¥£¥ì¥¯¥È¥ê¤òÊĤ¸¤Æ¤«¤é¾¤Î¥Ç¥£¥ì¥¯¥È¥ê¤ò¥ª¡¼¥×¥ó¤·Ä¾¤¹¤³¤È
106 ¤Ë¤Ê¤ë¤Î¤Ç¡¢
107 .BR ftw ()
108 ¤ÎÆ°ºî¤ÏÃÙ¤¯¤Ê¤ë¡£
109 .BR ftw ()
110 ¤Ï¡¢¥Ç¥£¥ì¥¯¥È¥ê¥Ä¥ê¡¼¤Î³¬ÁØ 1 ¥ì¥Ù¥ë¤Ë¤Ä¤­¡¢
111 ºÇÂç¤Ç¤â°ì¤Ä¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤·¤«»ÈÍѤ·¤Ê¤¤¡£
112
113 .\"O For each entry found in the tree,
114 .\"O .BR ftw ()
115 .\"O calls
116 .\"O \fIfn\fP() with three arguments:
117 .\"O .IR fpath ,
118 .\"O .IR sb ,
119 .\"O and
120 .\"O .IR typeflag .
121 ¥Ç¥£¥ì¥¯¥È¥ê¥Ä¥ê¡¼¤Ç¸«¤Ä¤«¤Ã¤¿¥¨¥ó¥È¥êËè¤Ë¡¢
122 .BR ftw ()
123 ¤Ï
124 .IR fpath ,
125 .IR sb ,
126 .I typeflag
127 ¤Î 3¤Ä¤ò°ú¤­¿ô¤È¤·¤Æ
128 .IR fn ()
129 ¤ò¸Æ¤Ó½Ð¤¹¡£
130 .\"O .I fpath
131 .\"O is the pathname of the entry,
132 .\"O and is expressed either as a pathname relative to the calling process's
133 .\"O current working directory at the time of the call to
134 .\"O .BR ftw (),
135 .\"O if
136 .\"O .IR dirpath
137 .\"O was expressed as a relative pathname,
138 .\"O or as an absolute pathname, if
139 .\"O .I dirpath
140 .\"O was expressed as an absolute pathname.
141 .I fpath
142 ¤Ï¥¨¥ó¥È¥ê¤Î¥Ñ¥¹Ì¾¤Ç¤¢¤ë¡£
143 .I dirpath
144 ¤¬ÁêÂХѥ¹Ì¾¤Ç»ØÄꤵ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢
145 .I fpath
146 ¤Ï
147 .BR ftw ()
148 ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿»þÅÀ¤Î¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤Î¥«¥ì¥ó¥È¥ï¡¼¥­¥ó¥°¥Ç¥£¥ì¥¯¥È¥ê
149 ¤«¤é¤ÎÁêÂХѥ¹Ì¾¤È¤Ê¤ë¡£
150 .I dirpath
151 ¤¬ÀäÂХѥ¹Ì¾¤Ç»ØÄꤵ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢
152 .I fpath
153 ¤ÏÀäÂХѥ¹Ì¾¤È¤Ê¤ë¡£
154 .\"O .I sb
155 .\"O is a pointer to the
156 .\"O .I stat
157 .\"O structure returned by a call to
158 .\"O .BR stat (2)
159 .\"O for
160 .\"O .IR fpath .
161 .I sb
162 ¤Ï
163 .I fpath
164 ¤ËÂФ¹¤ë
165 .BR stat (2)
166 ¤Î¸Æ¤Ó½Ð¤·¤ÇÊÖ¤µ¤ì¤ë
167 .I stat
168 ¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤Ç¤¢¤ë¡£
169 .\"O .I typeflag
170 .\"O is an integer that has one of the following values:
171 .I typeflag
172 ¤ÏÀ°¿ô¤Ç¡¢°Ê²¼¤ÎÃͤΤ¤¤º¤ì¤«°ì¤Ä¤Ç¤¢¤ë:
173 .TP
174 .B FTW_F
175 .\"O .I fpath
176 .\"O is a regular file.
177 .I fpath
178 ¤¬Ä̾ï¤Î¥Õ¥¡¥¤¥ë¤Ç¤¢¤ë
179 .TP
180 .B FTW_D
181 .\"O .I fpath
182 .\"O is a directory.
183 .I fpath
184 ¤¬¥Ç¥£¥ì¥¯¥È¥ê¤Ç¤¢¤ë
185 .TP
186 .B FTW_DNR
187 .\"O .I fpath
188 .\"O is a directory which can't be read.
189 .I fpath
190 ¤¬Æɤ߹þ¤ß¤Ç¤­¤Ê¤¤¥Ç¥£¥ì¥¯¥È¥ê¤Ç¤¢¤ë
191 .TP
192 .B FTW_NS
193 .\"O The
194 .\"O .BR stat (2)
195 .\"O call failed on
196 .\"O .IR fpath ,
197 .\"O which is not a symbolic link.
198 ¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤Ç¤Ï¤Ê¤¤
199 .I fpath
200 ¤ËÂФ¹¤ë
201 .BR stat (2)
202 ¸Æ¤Ó½Ð¤·¤¬¼ºÇÔ¤·¤¿¡£
203 .sp
204 .\"O If
205 .\"O .I fpath
206 .\"O is a symbolic link and
207 .\"O .BR stat (2)
208 .\"O failed, POSIX.1-2001 states
209 .\"O that it is undefined whether \fBFTW_NS\fP or \fBFTW_SL\fP (see below)
210 .\"O is passed in
211 .\"O .IR typeflag .
212 .I fpath
213 ¤¬¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤Ç¡¢¤«¤Ä
214 .BR stat (2)
215 ¤¬¼ºÇÔ¤·¤¿¾ì¹ç¡¢
216 .B FTW_NS
217 ¤È
218 .B FTW_SL
219 (¸å½Ò) ¤Î¤É¤Á¤é¤¬
220 .I typeflag
221 ¤ËÅϤµ¤ì¤ë¤«¤Ï̤ÄêµÁ¤Ç¤¢¤ë¤È¡¢POSIX.1-2001 ¤Ë¤Ï½ñ¤«¤ì¤Æ¤¤¤ë¡£
222 .PP
223 .\"O To stop the tree walk, \fIfn\fP() returns a nonzero value; this
224 .\"O value will become the return value of
225 .\"O .BR ftw ().
226 .\"O As long as \fIfn\fP() returns 0,
227 .\"O .BR ftw ()
228 .\"O will continue either until it has traversed the entire tree,
229 .\"O in which case it will return zero,
230 .\"O or until it encounters an error (such as a
231 .\"O .BR malloc (3)
232 .\"O failure), in which case it will return \-1.
233 ¥Ä¥ê¡¼¤Îõº÷¤ò»ß¤á¤¿¤¤¾ì¹ç¤Ï¡¢
234 .IR fn ()
235 ¤¬ 0 °Ê³°¤ÎÃͤòÊÖ¤»¤ÐÎɤ¤
236 (¤³¤ÎÃͤÏ
237 .BR ftw ()
238 ¼«¿È¤ÎÌá¤êÃͤȤʤë)¡£
239 ¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï
240 .BR ftw ()
241 ¤Ï¥Ä¥ê¡¼Á´ÂΤÎõº÷¤ò³¤±¡¢¤¹¤Ù¤Æ¤Î¥Ä¥ê¡¼¤òõº÷¤·½ª¤¨¤¿¤È¤³¤í¤Ç
242 0 ¤òÊÖ¤¹¡£Ãµº÷Ãæ¤Ë
243 .RB ( malloc (3)
244 ¤Î¼ºÇԤʤɤÎ) ¥¨¥é¡¼¤¬µ¯¤³¤ë¤È \-1 ¤òÊÖ¤¹¡£
245 .PP
246 .\"O Because
247 .\"O .BR ftw ()
248 .\"O uses dynamic data structures, the only safe way to
249 .\"O exit out of a tree walk is to return a nonzero value from \fIfn\fP().
250 .\"O To allow a signal to terminate the walk without causing a memory leak,
251 .\"O have the handler set a global flag that is checked by \fIfn\fP().
252 .\"O \fIDon't\fP use
253 .\"O .BR longjmp (3)
254 .\"O unless the program is going to terminate.
255 .BR ftw ()
256 ¤ÏưŪ¤Ê¥Ç¡¼¥¿¹½Â¤¤òÍѤ¤¤ë¤Î¤Ç¡¢¥Ä¥ê¡¼Ãµº÷¤ò°ÂÁ´¤ËÃæÃǤ¹¤ëÍ£°ì¤ÎÊýË¡¤Ï
257 0 °Ê³°¤ÎÃͤò
258 .IR fn ()
259 ¤ÎÊÖ¤êÃͤȤ¹¤ë¤³¤È¤Ç¤¢¤ë¡£³ä¤ê¹þ¤ß¤ò°·¤¦¤Ë¤Ï¡¢
260 Î㤨¤ÐȯÀ¸¤·¤¿³ä¤ê¹þ¤ß¤ò¥Þ¡¼¥¯¤·¤Æ¤ª¤¤¤Æ¡¢ 0 °Ê³°¤ÎÃͤòÊÖ¤¹¤è¤¦¤Ë¤¹¤ë
261 ¥·¥°¥Ê¥ë¤Ë¤è¤ê¥á¥â¥ê¥ê¡¼¥¯¤òµ¯¤³¤µ¤º¤Ëõº÷¤ò½ªÎ»¤Ç¤­¤ë¤è¤¦¤Ë¤¹¤ë¤Ë¤Ï¡¢
262 ¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ç
263 .IR fn ()
264 ¤¬¥Á¥§¥Ã¥¯¤¹¤ë¥°¥í¡¼¥Ð¥ë¤Ê¥Õ¥é¥°¤ò¥»¥Ã¥È¤¹¤ë¤è¤¦¤Ë¤¹¤ì¤Ð¤è¤¤¡£
265 ¥×¥í¥°¥é¥à¤ò½ªÎ»¤µ¤»¤ë¾ì¹ç°Ê³°¤Ï¡¢
266 .BR longjmp (3)
267 ¤ò»ÈÍѤ·¤Ê¤¤¤³¤È¡£
268 .SS nftw()
269 .\"O The function \fBnftw\fP() is the same as
270 .\"O .BR ftw (),
271 .\"O except that it has one additional argument, \fIflags\fP,
272 .\"O and calls \fIfn\fP() with one more argument, \fIftwbuf\fP.
273 ´Ø¿ô
274 .BR nftw ()
275 ¤Ï
276 .BR ftw ()
277 ¤ÈƱ¤¸¤À¤¬¡¢°ú¤­¿ô
278 .I flags
279 ¤¬Äɲ䵤ì¤ëÅÀ¤È¡¢
280 .IR fn ()
281 ¤Î°ú¤­¿ô¤Ë
282 .I ftwbuf
283 ¤¬Äɲ䵤ì¤ëÅÀ¤¬°Û¤Ê¤ë¡£
284
285 .\"O This \fIflags\fP argument is formed by ORing zero or more of the
286 .\"O following flags:
287 ¤³¤Î
288 .I flags
289 °ú¤­¿ô¤Ï²¼µ­¤Î¥Õ¥é¥°¤Î 0 ¸Ä°Ê¾å¤ÎÏÀÍýϤò¼è¤Ã¤¿¤â¤Î¤Ç¤¢¤ë:
290 .TP
291 .\"O .BR FTW_ACTIONRETVAL " (since glibc 2.3.3)"
292 .BR FTW_ACTIONRETVAL " (glibc 2.3.3 °Ê¹ß)"
293 .\"O If this glibc-specific flag is set, then
294 .\"O .BR nftw ()
295 .\"O handles the return value from
296 .\"O .IR fn ()
297 .\"O differently.
298 .\"O .IR fn ()
299 .\"O should return one of the following values:
300 ¤³¤Î¥Õ¥é¥°¤Ï glibc ¸ÇÍ­¤Ç¤¢¤ë¡£
301 ¤³¤Î¥Õ¥é¥°¤ò¥»¥Ã¥È¤¹¤ë¤È¡¢
302 .BR nftw ()
303 ¤Î
304 .IR fn ()
305 ¤ÎÊÖ¤êÃͤΰ·¤¤¤¬ÊѤï¤ë¡£
306 .IR fn ()
307 ¤Ï°Ê²¼¤ÎÃͤΤ¤¤º¤ì¤«°ì¤Ä¤òÊÖ¤¹É¬Íפ¬¤¢¤ë¡£
308 .RS
309 .TP
310 .B FTW_CONTINUE
311 .\"O Instructs
312 .\"O .BR nftw ()
313 .\"O to continue normally.
314 .BR nftw ()
315 ¤ÏÄ̾ïÄ̤ê½èÍý¤ò³¤±¤ë¡£
316 .TP
317 .B FTW_SKIP_SIBLINGS
318 .\"O If \fIfn\fP() returns this value, then
319 .\"O siblings of the current entry will be skipped,
320 .\"O and processing continues in the parent.
321 .IR fn ()
322 ¤¬¤³¤ÎÃͤòÊÖ¤·¤¿¾ì¹ç¡¢½èÍýÃæ¤Î¥¨¥ó¥È¥ê¤Î·»Äï (Ʊ¤¸³¬ÁؤΥ¨¥ó¥È¥ê)
323 ¤Î½èÍý¤Ï¥¹¥­¥Ã¥×¤µ¤ì¡¢¿Æ¥Ç¥£¥ì¥¯¥È¥ê¤Ç³¤­¤Î½èÍý¤¬¹Ô¤ï¤ì¤ë¡£
324 .\" If \fBFTW_DEPTH\fP
325 .\" is set, the entry's parent directory is processed next (with
326 .\" \fIflag\fP set to \fBFTW_DP\fP).
327 .TP
328 .B FTW_SKIP_SUBTREE
329 .\"O If \fIfn\fP() is called with an entry that is a directory
330 .\"O (\fItypeflag\fP is \fBFTW_D\fP), this return
331 .\"O value will prevent objects within that directory from being passed as
332 .\"O arguments to \fIfn\fP().
333 .\"O .BR nftw ()
334 .\"O continues processing with the next sibling of the directory.
335 .IR fn ()
336 ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿¥¨¥ó¥È¥ê¤¬¥Ç¥£¥ì¥¯¥È¥ê
337 .RI ( typeflag
338 ¤¬
339 .BR FTW_D )
340 ¤Î¾ì¹ç¤Ë¡¢¤³¤ÎÃͤòÊÖ¤¹¤È
341 .IR fn ()
342 ¤Î°ú¤­¿ô¤È¤·¤ÆÅϤµ¤ì¤¿¥Ç¥£¥ì¥¯¥È¥êÆâ¤Î¥¨¥ó¥È¥ê¤Î½èÍý¤¬¹Ô¤ï¤ì¤Ê¤¯¤Ê¤ë¡£
343 .BR nftw ()
344 ¤Ï½èÍýÃæ¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Î·»Äï (Ʊ¤¸³¬ÁؤΥ¨¥ó¥È¥ê) ¤«¤é½èÍý¤ò³¤±¤ë¡£
345 .TP
346 .B FTW_STOP
347 .\"O Causes
348 .\"O .BR nftw ()
349 .\"O to return immediately with the return value
350 .\"O \fBFTW_STOP\fP.
351 .B nftw ()
352 ¤Ï¡¢ÊÖ¤êÃÍ
353 .B FTW_STOP
354 ¤Ç¤¹¤°¤ËÉüµ¢¤¹¤ë¡£
355 .PP
356 .\"O Other return values could be associated with new actions in the future;
357 .\"O \fIfn\fP() should not return values other than those listed above.
358 ¾¤ÎÊÖ¤êÃͤϾ­Íè¿·¤·¤¤Æ°ºî¤ËÂбþÉÕ¤±¤é¤ì¤ë²ÄǽÀ­¤¬¤¢¤ë¡£
359 .IR fn ()
360 ¤Ï¾åµ­¤Î¥ê¥¹¥È¤Ë¤¢¤ëÃͰʳ°¤òÊÖ¤µ¤Ê¤¤¤è¤¦¤Ë¤¹¤Ù¤­¤Ç¤¢¤ë¡£
361
362 .\"O The feature test macro
363 .\"O .B _GNU_SOURCE
364 .\"O must be defined
365 .\"O (before including
366 .\"O .I any
367 .\"O header files)
368 .\"O in order to
369 .\"O obtain the definition of \fBFTW_ACTIONRETVAL\fP from \fI<ftw.h>\fP.
370 .I <ftw.h>
371 ¤Ç
372 .B FTW_ACTIONRETVAL
373 ¤ÎÄêµÁ¤¬Í­¸ú¤Ë¤¹¤ë¤¿¤á¤Ë¤Ï¡¢
374 (¡Ö¤É¤Î¡×¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤è¤ê¤âÁ°¤Ë)
375 µ¡Ç½¸¡ºº¥Þ¥¯¥í
376 .B _GNU_SOURCE
377 ¤òÄêµÁ¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
378 .RE
379 .TP
380 .B FTW_CHDIR
381 .\"O If set, do a
382 .\"O .BR chdir (2)
383 .\"O to each directory before handling its contents.
384 .\"O This is useful if the program needs to perform some action
385 .\"O in the directory in which \fIfpath\fP resides.
386 ¥»¥Ã¥È¤µ¤ì¤ë¤È¡¢¥Ç¥£¥ì¥¯¥È¥ê¤ÎÆâÍƤò½èÍý¤¹¤ëÁ°¤Ë
387 ¤½¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ë
388 .BR chdir (2)
389 ¤¹¤ë¡£¤³¤Î¥Õ¥é¥°¤Ï¡¢
390 .I fpath
391 ¤¬Â°¤¹¥Ç¥£¥ì¥¯¥È¥ê¤Ç²¿¤é¤«¤ÎÆ°ºî¤ò¼Â¹Ô¤¹¤ëɬÍפ¬¤¢¤ë¾ì¹ç¤Ë
392 ÊØÍø¤Ç¤¢¤ë¡£
393 .TP
394 .B FTW_DEPTH
395 .\"O If set, do a post-order traversal, that is, call \fIfn\fP() for
396 .\"O the directory itself \fIafter\fP handling the contents of the directory
397 .\"O and its subdirectories.
398 .\"O (By default, each directory is handled \fIbefore\fP its contents.)
399 ¥»¥Ã¥È¤µ¤ì¤ë¤È¡¢µ¢¤ê¤¬¤±½çõº÷ (post-order traversal) ¤ò¹Ô¤¦¡£
400 ¤Ä¤Þ¤ê¡¢¥Ç¥£¥ì¥¯¥È¥ê¤½¤Î¤â¤Î¤ò°ú¤­¿ô¤È¤·¤¿
401 .IR fn ()
402 ¸Æ½Ð¤·¤Ï¡¢¤½¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ë´Þ¤Þ¤ì¤ë¥Õ¥¡¥¤¥ë¤È¥µ¥Ö¥Ç¥£¥ì¥¯¥È¥ê¤Ë
403 ÂФ¹¤ë½èÍý¤Î¡Ö¸å¤Ç¡×¹Ô¤ï¤ì¤ë
404 (¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢¥Ç¥£¥ì¥¯¥È¥ê¼«¿È¤Î½èÍý¤Ï¥Ç¥£¥ì¥¯¥È¥êÆâ¤Î¥¨¥ó¥È¥ê
405 ¤è¤ê¡ÖÁ°¤Ë¡×¹Ô¤Ê¤ï¤ì¤ë)¡£
406 .TP
407 .B FTW_MOUNT
408 .\"O If set, stay within the same file system
409 .\"O (i.e., do not cross mount points).
410 ¥»¥Ã¥È¤µ¤ì¤ë¤È¡¢Æ±¤¸¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤ÎÃæ¤À¤±¤òõº÷ÂоݤȤ¹¤ë
411 (¤Ä¤Þ¤ê¡¢¥Þ¥¦¥ó¥È¥Ý¥¤¥ó¥È¤ò¤Þ¤¿¤°¤³¤È¤Ï¤Ê¤¤)¡£
412 .TP
413 .B FTW_PHYS
414 .\"O If set, do not follow symbolic links.
415 .\"O (This is what you want.)
416 .\"O If not set, symbolic links are followed, but no file is reported twice.
417 ¥»¥Ã¥È¤µ¤ì¤ë¤È¡¢¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤òé¤é¤Ê¤¤ (¤ª¤½¤é¤¯¤³¤Á¤é¤¬
418 Ä̾ï˾¤Þ¤·¤¤Æ°ºî¤À¤í¤¦)¡£¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¤È¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤ò
419 é¤ë¤¬¡¢Æ±¤¸¥Õ¥¡¥¤¥ë¤¬Æó²óÊó¹ð¤µ¤ì¤ë¤³¤È¤Ï¤Ê¤¤¡£
420 .sp
421 .\"O If \fBFTW_PHYS\fP is not set, but \fBFTW_DEPTH\fP is set,
422 .\"O then the function
423 .\"O .IR fn ()
424 .\"O is never called for a directory that would be a descendant of itself.
425 .B FTW_PHYS
426 ¤¬¥»¥Ã¥È¤µ¤ì¤º¤Ë
427 .B FTW_DEPTH
428 ¤¬¥»¥Ã¥È¤µ¤ì¤ë¤È¡¢¼«Ê¬¼«¿È¤ËÂФ¹¤ë¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤òÇÛ²¼¤Ë»ý¤Ä
429 ¥Ç¥£¥ì¥¯¥È¥ê¤ËÂФ·¤Æ
430 .IR fn ()
431 ¤¬¸Æ¤Ó½Ð¤µ¤ì¤ë¤³¤È¤Ï·è¤·¤Æ¤Ê¤¤¡£
432 .LP
433 .\"O For each entry in the directory tree,
434 .\"O .BR nftw ()
435 .\"O calls
436 .\"O .IR fn ()
437 .\"O with four arguments.
438 .\"O .I fpath
439 .\"O and
440 .\"O .I sb
441 .\"O are as for
442 .\"O .BR ftw ().
443 .\"O .I typeflag
444 .\"O may receive any of the same values as with
445 .\"O .BR ftw (),
446 .\"O or any of the following values:
447 ¥Ç¥£¥ì¥¯¥È¥ê¥Ä¥ê¡¼¤Î¥¨¥ó¥È¥êËè¤Ë¡¢
448 .BR nftw ()
449 ¤Ï 4¤Ä¤Î°ú¤­¿ô¤Ç
450 .IR fn ()
451 ¤ò¸Æ¤Ó½Ð¤¹¡£
452 .I fpath
453 ¤È
454 .I sb
455 ¤Ï
456 .BR ftw ()
457 ¤ÈƱ¤¸¤Ç¤¢¤ë¡£
458 .I typeflag
459 ¤Ë¤Ï¡¢
460 .BR ftw ()
461 ¤Ç¼è¤êÆÀ¤ëÃͤΤ¤¤º¤ì¤«¡¢¤Þ¤¿¤Ï°Ê²¼¤ÎÃͤΤ¤¤º¤ì¤«¤¬ÅϤµ¤ì¤ë:
462 .TP
463 .B FTW_DP
464 .\"O .I fpath
465 .\"O is a directory, and \fBFTW_DEPTH\fP was specified in \fIflags\fP.
466 .\"O All of the files
467 .\"O and subdirectories within \fIfpath\fP have been processed.
468 .I fpath
469 ¤¬¥Ç¥£¥ì¥¯¥È¥ê¤Ç¡¢¤«¤Ä
470 .I flags
471 ¤Ç
472 .B FTW_DEPTH
473 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤¿¡£
474 .I fpath
475 ÇÛ²¼¤Î¥Õ¥¡¥¤¥ë¤È¥µ¥Ö¥Ç¥£¥ì¥¯¥È¥ê¤ÏÁ´¤Æ½èÍý¤¬½ª¤ï¤Ã¤Æ¤¤¤ë¡£
476 .TP
477 .B FTW_SL
478 .\"O .I fpath
479 .\"O is a symbolic link, and \fBFTW_PHYS\fP was set in \fIflags\fP.
480 .I fpath
481 ¤¬¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤Ç¡¢¤«¤Ä \fBFTW_PHYS\fP ¤¬ \fIflags\fP ¤Ë
482 ¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤¿¡£
483 .\" To obtain the definition of this constant from
484 .\" .IR <ftw.h> ,
485 .\" either
486 .\" .B _BSD_SOURCE
487 .\" must be defined, or
488 .\" .BR _XOPEN_SOURCE
489 .\" must be defined with a value of 500 or more.
490 .TP
491 .B FTW_SLN
492 .\"O .I fpath
493 .\"O is a symbolic link pointing to a nonexistent file.
494 .\"O (This occurs only if \fBFTW_PHYS\fP is not set.)
495 .I fpath
496 ¤¬¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤Ç¡¢Â¸ºß¤·¤Ê¤¤¥Õ¥¡¥¤¥ë¤ò»Ø¤·¤Æ¤¤¤ë
497 (¤³¤ì¤¬¥»¥Ã¥È¤µ¤ì¤ë¤Î¤Ï
498 .B FTW_PHYS
499 ¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤À¤±¤Ç¤¢¤ë)¡£
500 .LP
501 .\"O The fourth argument that
502 .\"O .BR nftw ()
503 .\"O supplies when calling
504 .\"O \fIfn\fP()
505 .\"O is a structure of type \fIFTW\fP:
506 .BR nftw ()
507 ¤¬
508 .IR fn ()
509 ¤ò¸Æ¤Ó½Ð¤¹ºÝ¤ËÅϤ¹ 4¤Ä¤á¤Î°ú¤­¿ô¤Ï
510 .I FTW
511 ·¿¤Î¹½Â¤ÂΤǤ¢¤ë¡£
512 .in +4n
513 .nf
514
515 struct FTW {
516     int base;
517     int level;
518 };
519
520 .fi
521 .in
522 .\"O .I base
523 .\"O is the offset of the filename (i.e., basename component)
524 .\"O in the pathname given in
525 .\"O .IR fpath .
526 .\"O .I level
527 .\"O is the depth of
528 .\"O .I fpath
529 .\"O in the directory tree, relative to the root of the tree
530 .\"O .RI ( dirpath ,
531 .\"O which has depth 0).
532 .I base
533 ¤Ï¡¢¥Õ¥¡¥¤¥ë̾ (basename Í×ÁÇ) ¤Î¡¢
534 .I fpath
535 ¤ÇÅϤµ¤ì¤ë¥Ñ¥¹Ì¾¤ÎÃæ¤Ç¤Î¥ª¥Õ¥»¥Ã¥È¤Ç¤¢¤ë¡£
536 .I level
537 ¤Ï¥Ç¥£¥ì¥¯¥È¥ê¥Ä¥ê¡¼¤Ç¤Î
538 .I fpath
539 ¤Î¿¼¤µ¤ò¼¨¤¹¡£¿¼¤µ¤Ï¥Ç¥£¥ì¥¯¥È¥ê¥Ä¥ê¡¼¤Î¥È¥Ã¥× (root) ¤«¤é¤Î
540 ÁêÂÐÃͤǤ¢¤ë
541 .RI ( dirpath
542 ¤Ï¿¼¤µ 0 ¤Ç¤¢¤ë)¡£
543 .\"O .SH "RETURN VALUE"
544 .SH ÊÖ¤êÃÍ
545 .\"O These functions return 0 on success, and \-1 if an error occurs.
546 ¤³¤ì¤é¤Î´Ø¿ô¤Ï¡¢À®¸ù¤¹¤ë¤È 0 ¤ò¡¢¥¨¥é¡¼¤¬È¯À¸¤¹¤ë¤È \-1 ¤òÊÖ¤¹¡£
547
548 .\"O If \fIfn\fP() returns nonzero,
549 .\"O then the tree walk is terminated and the value returned by \fIfn\fP()
550 .\"O is returned as the result of \fBftw\fP() or
551 .\"O .BR nftw ().
552 .IR fn ()
553 ¤¬ 0 °Ê³°¤òÊÖ¤·¤¿¾ì¹ç¡¢¥Ç¥£¥ì¥¯¥È¥ê¥Ä¥ê¡¼¤Îõº÷¤ò½ªÎ»¤·¡¢
554 .IR fn ()
555 ¤¬ÊÖ¤·¤¿Ãͤò
556 .BR ftw ()
557 ¤ä
558 .BR nftw ()
559 ¤Î·ë²Ì¤È¤·¤ÆÊÖ¤¹¡£
560
561 .\"O If
562 .\"O .BR nftw ()
563 .\"O is called with the \fBFTW_ACTIONRETVAL\fP flag,
564 .\"O then the only nonzero value that should be used by \fIfn\fP()
565 .\"O to terminate the tree walk is \fBFTW_STOP\fP,
566 .\"O and that value is returned as the result of
567 .\"O .BR nftw ().
568 .BR nftw ()
569 ¤¬
570 .B FTW_ACTIONRETVAL
571 ¥Õ¥é¥°ÉÕ¤­¤Ç¸Æ¤Ð¤ì¤¿¾ì¹ç¡¢¥Ä¥ê¡¼¤Îõº÷¤ò½ªÎ»¤µ¤»¤ë¤¿¤á¤Ë
572 .IR fn ()
573 ¤¬»ÈÍѤǤ­¤ë¡¢Èó 0 ¤ÎÃͤÏ
574 .B FTW_STOP
575 ¤À¤±¤Ç¤¢¤ê¡¢
576 ¤³¤ÎÃͤÏ
577 .BR nftw ()
578 ¤ÎÊÖ¤êÃͤȤ·¤ÆÊÖ¤µ¤ì¤ë¡£
579 .\"O .SH "CONFORMING TO"
580 .SH ½àµò
581 POSIX.1-2001, SVr4, SUSv1.
582 .\"O POSIX.1-2008 marks
583 .\"O .BR ftw ()
584 .\"O as obsolete.
585 POSIX.1-2008 ¤Ï
586 .BR ftw ()
587 ¤òÇÑ»ßͽÄê¤È¤·¤Æ¤¤¤ë¡£
588 .\"O .SH NOTES
589 .SH Ãí°Õ
590 .\"O POSIX.1-2001 note that the results are unspecified if
591 .\"O .I fn
592 .\"O does not preserve the current working directory.
593 POSIX.1-2001 ¤ÎÃíµ­¤Ë¤è¤ë¤È¡¢
594 .I fn
595 ¤¬¥«¥ì¥ó¥È¥ï¡¼¥­¥ó¥°¥Ç¥£¥ì¥¯¥È¥ê¤òÊÝ»ý¤·¤Ê¤«¤Ã¤¿¾ì¹ç¤Î
596 ·ë²Ì¤Ïµ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤¤È¤µ¤ì¤Æ¤¤¤ë¡£
597 .PP
598 .\"O The function
599 .\"O .BR nftw ()
600 .\"O and the use of \fBFTW_SL\fP with
601 .\"O .BR ftw ()
602 .\"O were introduced in SUSv1.
603 .BR nftw ()
604 ´Ø¿ô¤È¡¢
605 .BR ftw ()
606 ¤Ë¤ª¤±¤ë
607 .B FTW_SL
608 ¤Ï¡¢SUSv1 ¤ÇƳÆþ¤µ¤ì¤¿¡£
609 .LP
610 .\"O On some systems
611 .\"O .BR ftw ()
612 .\"O will never use \fBFTW_SL\fP, on other systems \fBFTW_SL\fP occurs only
613 .\"O for symbolic links that do not point to an existing file,
614 .\"O and again on other systems
615 .\"O .BR ftw ()
616 .\"O will use \fBFTW_SL\fP for each symbolic link.
617 .\"O For predictable control, use
618 .\"O .BR nftw ().
619 .BR ftw ()
620 ¤Ç
621 .B FTW_SL
622 ¤ò°ìÀڻȤï¤Ê¤¤¥·¥¹¥Æ¥à¤ä¡¢
623 ¸ºß¤·¤Ê¤¤¥Õ¥¡¥¤¥ë¤ò»Ø¤·¤Æ¤¤¤ë¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤Î¾ì¹ç¤Ë¤Î¤ß
624 .B FTW_SL
625 ¤ò»È¤¦¥·¥¹¥Æ¥à¡¢¤Þ¤¿
626 .BR ftw ()
627 ¤¬Á´¤Æ¤Î¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤ËÂФ·¤Æ
628 .B FTW_SL
629 ¤ò»È¤¦¥·¥¹¥Æ¥à¤â¤¢¤ë¡£
630 ͽ¬²Äǽ¤ÊÆ°ºî¤ò¤µ¤»¤ë¤¿¤á¤Ë¤Ï¡¢
631 .BR nftw ()
632 ¤ò»È¤¦¤³¤È¡£
633 .LP
634 .\"O Under Linux, libc4 and libc5 and glibc 2.0.6 will
635 .\"O use \fBFTW_F\fP for all objects (files, symbolic links, FIFOs, etc.)
636 .\"O that can be stat'ed but are not a directory.
637 Linux ¤Ç¤Ï¡¢ libc4, libc5, glibc 2.0.6 ¤Ï
638 ¡Östat ¤Ç¤­¤ë¤¬¥Ç¥£¥ì¥¯¥È¥ê¤Ç¤Ï¤Ê¤¤¥ª¥Ö¥¸¥§¥¯¥È¡×
639 (¥Õ¥¡¥¤¥ë, ¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯, fifo Åù)
640 ¤ËÂФ·¤Æ¤Ï¤¹¤Ù¤Æ
641 .B FTW_F
642 ¤ò»È¤¦¡£
643
644 .\"O The function
645 .\"O .BR nftw ()
646 .\"O is available since glibc 2.1.
647 .BR nftw ()
648 ´Ø¿ô¤Ï glibc 2.1 °Ê¹ß¤ÇÍøÍѤǤ­¤ë¡£
649
650 .\"O \fBFTW_ACTIONRETVAL\fP is glibc-specific.
651 .B FTW_ACTIONRETVAL
652 ¤Ï glibc ¸ÇÍ­¤Ç¤¢¤ë¡£
653 .\"O .SH EXAMPLE
654 .SH Îã
655 .\"O The following program traverses the directory tree under the path named
656 .\"O in its first command-line argument, or under the current directory
657 .\"O if no argument is supplied.
658 .\"O It displays various information about each file.
659 .\"O The second command-line argument can be used to specify characters that
660 .\"O control the value assigned to the \fIflags\fP
661 .\"O argument when calling
662 .\"O .BR nftw ().
663 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢°ì¤ÄÌܤΥ³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤ò̾Á°¤Ë»ý¤Ä¥Ñ¥¹°Ê²¼¤Î
664 ¥Ç¥£¥ì¥¯¥È¥ê¥Ä¥ê¡¼¤òõº÷¤¹¤ë¡£°ú¤­¿ô¤¬»ØÄꤵ¤ì¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï¡¢
665 ¥«¥ì¥ó¥È¥Ç¥£¥ì¥¯¥È¥ê°Ê²¼¤òõº÷¤¹¤ë¡£
666 ³Æ¡¹¤Î¥Õ¥¡¥¤¥ë¤Ë¤Ä¤¤¤ÆÍÍ¡¹¤Î¾ðÊó¤¬É½¼¨¤µ¤ì¤ë¡£
667 ÆóÈÖÌܤΥ³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤Ëʸ»ú¤ò»ØÄꤹ¤ë¤³¤È¤Ç¡¢
668 .BR nftw ()
669 ¤ò¸Æ¤Ó½Ð¤¹ºÝ¤Ë
670 .I flags
671 °ú¤­¿ô¤ËÅϤ¹ÃͤòÀ©¸æ¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
672 .nf
673
674 #define _XOPEN_SOURCE 500
675 #include <ftw.h>
676 #include <stdio.h>
677 #include <stdlib.h>
678 #include <string.h>
679 #include <stdint.h>
680
681 static int
682 display_info(const char *fpath, const struct stat *sb,
683              int tflag, struct FTW *ftwbuf)
684 {
685     printf("%\-3s %2d %7jd   %\-40s %d %s\\n",
686         (tflag == FTW_D) ?   "d"   : (tflag == FTW_DNR) ? "dnr" :
687         (tflag == FTW_DP) ?  "dp"  : (tflag == FTW_F) ?   "f" :
688         (tflag == FTW_NS) ?  "ns"  : (tflag == FTW_SL) ?  "sl" :
689         (tflag == FTW_SLN) ? "sln" : "???",
690         ftwbuf\->level, (intmax_t) sb\->st_size,
691         fpath, ftwbuf\->base, fpath + ftwbuf\->base);
692     return 0;           /* To tell nftw() to continue */
693 }
694
695 int
696 main(int argc, char *argv[])
697 {
698     int flags = 0;
699
700     if (argc > 2 && strchr(argv[2], \(aqd\(aq) != NULL)
701         flags |= FTW_DEPTH;
702     if (argc > 2 && strchr(argv[2], \(aqp\(aq) != NULL)
703         flags |= FTW_PHYS;
704
705     if (nftw((argc < 2) ? "." : argv[1], display_info, 20, flags)
706             == \-1) {
707         perror("nftw");
708         exit(EXIT_FAILURE);
709     }
710     exit(EXIT_SUCCESS);
711 }
712 .fi
713 .\"O .SH "SEE ALSO"
714 .SH ´ØÏ¢¹àÌÜ
715 .BR stat (2),
716 .BR fts (3),
717 .BR readdir (3)