AT&T UNIX™PC Unix System V Users Manual - tenox
AT&T UNIX™PC Unix System V Users Manual - tenox AT&T UNIX™PC Unix System V Users Manual - tenox
FTW(3C) FTW(3C) NAME ftw - walk a file tree SYNOPSIS #include int ftw (path, fn , depth) char *path; int (*fn) ( ); int depth; DESCRIPTION Ftw recursively descends the directory hierarchy rooted in path . For each object in the hierarchy, ftw calls fn , passing it a pointer to a null-terminated character string containing the name of the object, a pointer to a stat structure (see stat(2)) containing information about the object, and an integer. Possible values of the integer, defined in the header file, are FTW_F for a file, FTW_D for a directory, FTW_DNR for a directory that cannot be read, and FTW_NS for an object for which stat could not successfully be executed. If the integer is FTW _DNR, descendants of that directory will not be processed. If the integer is FTW _NS, the stat structure will contain garbage. An example of an object that would cause FTW _NS to be passed to fn would be a file in a directory with read but without execute (search) permission. Ftw visits a directory before visiting any of its descendants. The tree traversal continues until the tree is exhausted, an invocation of fn returns a nonzero value, or some error is detected within ftw (such as an 1/0 error). If the tree is exhausted, ftw returns zero. If fn returns a nonzero value, ftw stops its tree traversal and returns whatever value was returned by fn . If ftw detects an error, it returns -1, and sets the error type in errno. Ftw uses one file descriptor for each level in the tree. The depth argument limits the number of file descriptors so used. If depth is zero or negative, the effect is the same as if it were 1. Depth must not be greater than the number of file descriptors currently available for use. Ftw will run more quickly if depth is at least as large as the number of levels in the tree. SEE ALSO stat(2), malloc(3C). BUGS Because ftw is recursive, it is possible for it to terminate with a memory fault when applied to very deep file structures. It could be made to run faster and use less storage on deep structures at the cost of considerable complexity. Ftw uses malloc(3C) to allocate dynamic storage during its operation. If ftw is forcibly terminated, such as by longjmp being executed by fn or an interrupt routine, ftw will not have a chance to free that storage, so it will remain permanently allocated. A safe way to handle interrupts is to store the fact that an interrupt has occurred, and arrange to have fn return a nonzero value at its next invocation. - 1 -
- Page 803: CLOCK( 3C ) CLOCK( 3C ) NAME clock
- Page 806 and 807: J ··- � . ..._ __ .·
- Page 809: CTERMID ( 3S ) CTERMID ( 3S ) NAME
- Page 812 and 813: CTIME (3C) CTIME(3C) The external l
- Page 815 and 816: CURSES ( 3 ) CURSES ( 3 ) NAME curs
- Page 817 and 818: CUSERID ( 3S ) CUSERID ( 3S ) NAME
- Page 819 and 820: DIAL (3C) DIAL(3C) NAME dial - esta
- Page 821 and 822: DRAND48 ( 3C ) DRAND48 ( 3C ) NAME
- Page 823 and 824: DRAND48 ( 3C ) DRAND48 ( 3C ) have
- Page 825: ECVT (3C) ECVT (3C) NAME ecvt, fcvt
- Page 829 and 830: EPRINTF ( 3T ) ( AT&T UNIX PC only
- Page 831 and 832: ERF (3M) ERF (3M) NAME erf1 erfc -
- Page 833: EXP ( 3M ) EXP ( 3M ) NAME exp, log
- Page 837: FERROR (3S) FERROR (3S) NAME ferror
- Page 841 and 842: FOPEN(3S) FOPEN (3S) NAME fopen, fr
- Page 843 and 844: FORM ( 3T ) ( AT&T UNIX PC only ) F
- Page 845 and 846: FORM (3T) (AT&T UNIX PC only ) fiel
- Page 847 and 848: FORM (3T) }; (AT&T UNIX PC only ) F
- Page 849: FREAD ( 3S ) FREAD ( 3S ) NAME frea
- Page 853: FSEEK ( 3S ) FSEEK ( 3S ) NAME fsee
- Page 858 and 859: �·. (
- Page 860 and 861: I� i -� ·-
- Page 863: GETENV (3C) NAME getenv - return va
- Page 866 and 867: GETGRENT ( 3C ) GETGRENT ( 3C ) WAR
- Page 869 and 870: GETOPT (3C) GETOPT (3C) NAME getopt
- Page 871: GETP ASS ( 3C ) GETP ASS ( 3C ) NAM
- Page 874 and 875: � ' ) '"- '
- Page 877 and 878: GETPWENT ( 30 ) GETPWENT ( 30 ) NAM
- Page 879: GETS ( 3S ) GETS ( 3S ) NAME gets,
- Page 882 and 883: GETUT (3C) GETUT (3C) line-> ut_lin
- Page 884 and 885: HSEARCH ( 3C ) HSEARCH ( 3C ) START
- Page 886 and 887: I� ', ...____... .. � · � \
- Page 889 and 890: LDAHREAD ( 3X ) LDAI-IREAD ( 3X ) N
- Page 891: LDCLOSE ( 3X ) LDCLOSE ( 3X ) NAME
- Page 895: LDLREAD ( 3X ) LDLREAD ( 3X ) NAME
- Page 898 and 899: . \
- Page 900 and 901: �� · ·. � ·
- Page 902 and 903: LDOPEN(3X) LDOPEN(3X) example, one
FTW(3C) FTW(3C)<br />
NAME<br />
ftw - walk a file tree<br />
SYNOPSIS<br />
#include <br />
int ftw (path, fn , depth)<br />
char *path;<br />
int (*fn) ( );<br />
int depth;<br />
DESCRIPTION<br />
Ftw recursively descends the directory hierarchy rooted in path .<br />
For each object in the hierarchy, ftw calls fn , passing it a pointer<br />
to a null-terminated character string containing the name of the<br />
object, a pointer to a stat structure (see stat(2)) containing information<br />
about the object, and an integer. Possible values of the<br />
integer, defined in the header file, are FTW_F for a file,<br />
FTW_D for a directory, FTW_DNR for a directory that cannot be<br />
read, and FTW_NS for an object for which stat could not successfully<br />
be executed. If the integer is FTW _DNR, descendants of that<br />
directory will not be processed. If the integer is FTW _NS, the stat<br />
structure will contain garbage. An example of an object that<br />
would cause FTW _NS to be passed to fn would be a file in a directory<br />
with read but without execute (search) permission.<br />
Ftw visits a directory before visiting any of its descendants.<br />
The tree traversal continues until the tree is exhausted, an invocation<br />
of fn returns a nonzero value, or some error is detected<br />
within ftw (such as an 1/0 error). If the tree is exhausted, ftw<br />
returns zero. If fn returns a nonzero value, ftw stops its tree<br />
traversal and returns whatever value was returned by fn . If ftw<br />
detects an error, it returns -1, and sets the error type in errno.<br />
Ftw uses one file descriptor for each level in the tree. The depth<br />
argument limits the number of file descriptors so used. If depth is<br />
zero or negative, the effect is the same as if it were 1. Depth must<br />
not be greater than the number of file descriptors currently available<br />
for use. Ftw will run more quickly if depth is at least as<br />
large as the number of levels in the tree.<br />
SEE ALSO<br />
stat(2), malloc(3C).<br />
BUGS<br />
Because ftw is recursive, it is possible for it to terminate with a<br />
memory fault when applied to very deep file structures.<br />
It could be made to run faster and use less storage on deep structures<br />
at the cost of considerable complexity.<br />
Ftw uses malloc(3C) to allocate dynamic storage during its operation.<br />
If ftw is forcibly terminated, such as by longjmp being executed<br />
by fn or an interrupt routine, ftw will not have a chance to<br />
free that storage, so it will remain permanently allocated. A safe<br />
way to handle interrupts is to store the fact that an interrupt has<br />
occurred, and arrange to have fn return a nonzero value at its<br />
next invocation.<br />
- 1 -