1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
|
.\" Copyright (c) 1993 Michael Haardt (u31b3hs@pool.informatik.rwth-aachen.de)
.\" and copyright (c) 1999 Andries Brouwer (aeb@cwi.nl)
.\" and copyright (c) 2006 Justin Pryzby <justinpryzby@users.sf.net>
.\" and copyright (c) 2006 Michael Kerrisk <mtk-manpages@gmx.net>
.\"
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" the License, or (at your option) any later version.
.\"
.\" The GNU General Public License's references to "object code"
.\" and "executables" are to be interpreted as the output of any
.\" document formatting or typesetting system, including
.\" intermediate and printed output.
.\"
.\" This manual is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public
.\" License along with this manual; if not, write to the Free
.\" Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
.\" USA.
.\"
.\" Modified Sun Jul 25 11:02:22 1993 by Rik Faith (faith@cs.unc.edu)
.\" 2006-05-24, Justin Pryzby <justinpryzby@users.sf.net>
.\" document FTW_ACTIONRETVAL; include .SH "RETURN VALUE";
.\" 2006-05-24, Justin Pryzby <justinpryzby@users.sf.net> and
.\" Michael Kerrisk <mtk-manpages@gmx.net>
.\" reorganized and rewrote much of the page
.\" 2006-05-24, Michael Kerrisk <mtk-manpages@gmx.net>
.\" Added an example program.
.\"
.\" Japanese Version Copyright (c) 1998 NAKANO Takeo all rights reserved.
.\" Translated 1998-04-28, NAKANO Takeo <nakano@apm.seikei.ac.jp>
.\" Updated & Modified 1999-09-14, NAKANO Takeo <nakano@apm.seikei.ac.jp>
.\" Updated & Modified 2005-11-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
.\" Updated 2006-07-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.36
.\"
.\" WORD: file descriptor եǥץ
.\"
.TH FTW 3 2006-05-24 "Linux" "Linux Programmer's Manual"
.SH ̾
ftw, nftw \- եĥ⤭ޤ
.SH
.nf
.B #include <ftw.h>
.sp
.BI "int ftw(const char *" dirpath ,
.BR " int (*" fn ") (const char *" fpath ", const struct stat *" sb ,
.BI " int " typeflag ),
.BI " int " nopenfd );
.sp
.B #define _XOPEN_SOURCE 500
.B #include <ftw.h>
.sp
.BI "int nftw(const char *" dirpath ,
.BI " int (*" fn ") (const char *" fpath ", const struct stat *" sb ,
.BI " int " typeflag ", struct FTW *" ftwbuf ),
.BI " int " nopenfd ", int " flags );
.fi
.SH
.BR ftw ()
ϡ
.I dirpath
ǻꤵ줿ǥ쥯ȥʲΥǥ쥯ȥĥΤ⤭ޤꡢ
ĥǥȥ꤬դ뤴Ȥˡ
.IR fn ()
ƤӽФ
ǥեȤǤϡǥ쥯ȥꤽΤΤΥǥ쥯ȥˤե
֥ǥ쥯ȥ˽ (Ԥõ; pre-order traversal)
ƤӽФץѲǽʥեǥץȤڤä
ޤʤ褦ˤ뤿ᡢ
.BR ftw ()
Ʊ˥ץǥ쥯ȥκ
.I nopenfd
ǻꤹ뤳ȤǤ롣
õοͤۤȡ
ĤΥǥ쥯ȥĤƤ¾Υǥ쥯ȥץľ
ˤʤΤǡ
.BR ftw ()
ư٤ʤ롣
.BR ftw ()
ϡǥ쥯ȥĥγ 1 ٥ˤĤ
ǤĤΥեǥץѤʤ
ǥ쥯ȥĥǸĤäȥˡ
.BR ftw ()
.IR fpath ,
.IR sb ,
.I typeflag
3ĤȤ
.IR fn ()
ƤӽФ
.I fpath
ϥȥ
.I dirpath
Хѥ̾Ǥ롣
.I sb
.I fpath
Ф
.BR stat (2)
θƤӽФ֤
.I stat
¤ΤؤΥݥǤ롣
.I typeflag
ǡʲͤΤ줫ĤǤ:
.TP
.B FTW_F
.I fpath
̾ΥեǤ
.TP
.B FTW_D
.I fpath
ǥ쥯ȥǤ
.TP
.B FTW_DNR
.I fpath
ɤ߹ߤǤʤǥ쥯ȥǤ
.TP
.B FTW_NS
ܥåǤϤʤ
.I fpath
Ф
.BR stat (2)
ƤӽФԤ
.sp
.I fpath
ܥåǡ
.BR stat (2)
Ԥ硢
.B FTW_NS
.B FTW_SL
() Τɤ餬
.I typeflag
Ϥ뤫̤ǤȡPOSIX.1-2001 ˤϽƤ롣
.PP
ĥõߤϡ
.IR fn ()
0 ʳ֤ͤɤ
(ͤ
.BR ftw ()
ȤͤȤʤ)
ʳξ
.BR ftw ()
ϥĥΤõ³٤ƤΥĥõȤ
0 ֤õ
.RB ( malloc (3)
μԤʤɤ) 顼 \-1 ֤
.PP
.BR ftw ()
ưŪʥǡ¤ѤΤǡĥõǤͣˡ
0 ʳͤ
.IR fn ()
֤ͤȤ뤳ȤǤ롣ߤˤϡ
㤨ȯߤޡƤơ 0 ʳ֤ͤ褦ˤ
ʥˤõλǤ褦ˤˤϡ
ʥϥɥ
.IR fn ()
å륰Хʥե饰åȤ褦ˤФ褤
ץλʳϡ
.BR longjmp (3)
Ѥʤȡ
.SS nftw()
ؿ
.BR nftw ()
.BR ftw ()
Ʊ
.I flags
ɲäȡ
.IR fn ()
ΰ
.I ftwbuf
ɲäۤʤ롣
.I flags
ϲΥե饰 0 İʾ¤äΤǤ:
.TP
.BR FTW_ACTIONRETVAL " (glibc 2.3.3 ʹ)"
Υե饰 glibc ͭǤ롣
Υե饰åȤȡ
.BR nftw ()
.IR fn ()
֤ͤΰѤ롣
.IR fn ()
ϰʲͤΤ줫Ĥ֤ɬפ롣
.RS
.TP
.B FTW_CONTINUE
.BR nftw ()
̤̾³롣
.TP
.B FTW_SKIP_SIBLINGS
.IR fn ()
֤ͤ硢Υȥη (ƱؤΥȥ)
νϥåפ졢ƥǥ쥯ȥ³νԤ롣
.\" If \fBFTW_DEPTH\fP
.\" is set, the entry's parent directory is processed next (with
.\" \fIflag\fP set to \fBFTW_DP\fP).
.TP
.B FTW_SKIP_SUBTREE
.IR fn ()
ƤӽФ줿ȥ꤬ǥ쥯ȥ
.RI ( typeflag
.BR FTW_D )
ξˡ֤ͤ
.IR fn ()
ΰȤϤ줿ǥ쥯ȥΥȥνԤʤʤ롣
.BR nftw ()
ϽΥǥ쥯ȥη (ƱؤΥȥ) ³롣
.TP
.B FTW_STOP
.B nftw ()
ϡ֤
.B FTW_STOP
Ǥ롣
.PP
¾֤ͤϾ迷ưбդǽ롣
.IR fn ()
Ͼ嵭ΥꥹȤˤͰʳ֤ʤ褦ˤ٤Ǥ롣
.I <ftw.h>
.B FTW_ACTIONRETVAL
褦ˤˤϡ
ǽޥ _GNU_SOURCE ʤФʤʤ
.RE
.TP
.B FTW_CHDIR
åȤȡǥ쥯ȥƤ
Υǥ쥯ȥ
.BR chdir (2)
롣Υե饰ϡ
.I fpath
°ǥ쥯ȥDz餫ư¹Ԥɬפ
Ǥ롣
.TP
.B FTW_DEPTH
åȤȡ꤬õ (post-order traversal) Ԥ
Ĥޤꡢǥ쥯ȥꤽΤΤȤ
.IR fn ()
ƽФϡΥǥ쥯ȥ˴ޤޤեȥ֥ǥ쥯ȥ
ФΡָǡԤ
(ǥեȤǤϡǥ쥯ȥ꼫Ȥνϥǥ쥯ȥΥȥ
ˡԤʤ)
.TP
.B FTW_MOUNT
åȤȡƱե륷ƥõоݤȤ
(ĤޤꡢޥȥݥȤޤȤϤʤ)
.TP
.B FTW_PHYS
åȤȡܥåéʤ (餯餬
̾˾ޤư)åȤƤʤȥܥå
é뤬Ʊե뤬𤵤뤳ȤϤʤ
.sp
.B FTW_PHYS
åȤ줺
.B FTW_DEPTH
åȤȡʬȤФ륷ܥå۲˻
ǥ쥯ȥФ
.IR fn ()
ƤӽФ뤳ȤϷ褷Ƥʤ
.LP
ǥ쥯ȥĥΥȥˡ
.BR nftw ()
4Ĥΰ
.IR fn ()
ƤӽФ
.I fpath
.I sb
.BR ftw ()
ƱǤ롣
.I typeflag
ˤϡ
.BR ftw ()
ǼͤΤ줫ޤϰʲͤΤ줫Ϥ:
.TP
.B FTW_DP
.I fpath
ǥ쥯ȥǡ
.I flags
.B FTW_DEPTH
ꤵƤ
.I fpath
۲Υեȥ֥ǥ쥯ȥƽäƤ롣
.TP
.B FTW_SL
.I fpath
ܥåǡ \fBFTW_PHYS\fP \fIflags\fP
åȤƤ
.TP
.B FTW_SLN
.I fpath
ܥåǡ¸ߤʤեؤƤ
(줬åȤΤ
.B FTW_PHYS
åȤƤʤǤ)
.LP
.BR nftw ()
.IR fn ()
ƤӽФݤϤ 4Ĥΰ
.I FTW
ι¤ΤǤ롣
.in +0.25i
.nf
struct FTW {
int base;
int level;
};
.fi
.in -0.25i
.I base
ϡե̾ (basename ) Ρ
.I fpath
Ϥѥ̾ǤΥեåȤǤ롣
.I level
ϥǥ쥯ȥĥǤ
.I fpath
οϥǥ쥯ȥĥΥȥå (root)
ͤǤ
.RI ( dirpath
Ͽ 0 Ǥ)
.SH ֤
δؿϡ 0 顼ȯ \-1 ֤
.BR fn ()
0 ʳ֤硢ǥ쥯ȥĥõλ
.BR fn ()
֤ͤ
.BR ftw ()
.BR nftw ()
η̤Ȥ֤
.BR nftw ()
.B FTW_ACTIONRETVAL
ե饰դǸƤФ줿硢ĥõλ뤿
.IR fn ()
ѤǤ롢 0 ͤ
.B FTW_STOP
Ǥꡢ
ͤ
.BR nftw ()
֤ͤȤ֤롣
.SH
.BR nftw ()
ؿȡ
.BR ftw ()
ˤ
.B FTW_SL
ϡSUSv1 Ƴ줿
.LP
.BR ftw ()
.B FTW_SL
ڻȤʤƥ䡢
¸ߤʤեؤƤ륷ܥåξˤΤ
.B FTW_SL
Ȥƥࡢޤ
.BR ftw ()
ƤΥܥåФ
.B FTW_SL
Ȥƥ⤢롣
ͽ¬ǽư뤿ˤϡ
.BR nftw ()
Ȥȡ
.LP
Linux Ǥϡ libc4, libc5, glibc 2.0.6
stat Ǥ뤬ǥ쥯ȥǤϤʤ֥ȡ
(ե, ܥå, fifo )
ФƤϤ٤
.B FTW_F
Ȥ
.BR nftw ()
ؿ glibc 2.1 ʹߤѤǤ롣
.B FTW_ACTIONRETVAL
glibc ͭǤ롣
.SH
POSIX.1-2001, SVr4, SUSv1.
.SH
ʲΥץϡܤΥޥɥ饤̾˻ĥѥʲ
ǥ쥯ȥĥõ롣ꤵʤäϡ
ȥǥ쥯ȥʲõ롣
ơΥեˤĤ͡ξɽ롣
ܤΥޥɥ饤ʸꤹ뤳Ȥǡ
.BR nftw ()
ƤӽФݤ
.I flags
Ϥͤ椹뤳ȤǤ롣
.nf
#define _XOPEN_SOURCE 500
#include <ftw.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int
display_info(const char *fpath, const struct stat *sb,
int tflag, struct FTW *ftwbuf)
{
printf("%-3s %2d %7lld %-40s %d %s\\n",
(tflag == FTW_D) ? "d" : (tflag == FTW_DNR) ? "dnr" :
(tflag == FTW_DP) ? "dp" : (tflag == FTW_F) ? "f" :
(tflag == FTW_DP) ? "dp" : (tflag == FTW_SL) ? "sl" :
(tflag == FTW_SLN) ? "sln" : "???",
ftwbuf->level, (long long) sb->st_size,
fpath, ftwbuf->base, fpath + ftwbuf->base);
return 0; /* To tell nftw() to continue */
}
int
main(int argc, char *argv[])
{
int flags = 0;
if (argc > 2 && strchr(argv[2], 'd') != NULL)
flags |= FTW_DEPTH;
if (argc > 2 && strchr(argv[2], 'p') != NULL)
flags |= FTW_PHYS;
nftw((argc < 2) ? "." : argv[1], display_info, 20, flags);
exit(EXIT_SUCCESS);
}
.fi
.SH Ϣ
.BR stat (2),
.BR fts (3),
.BR readdir (3)
|