[Linux manuál]
Návod, kniha: POSIX Programmer's Manual
int ftw(const char * path, int
(*fn )(const char *,
const struct stat *
ptr , int flag),
int ndirs);
ftw: procházet (procházet) strom souborů
Originální popis anglicky: ftw - traverse (walk) a file treeNávod, kniha: POSIX Programmer's Manual
STRUČNĚ
#include <ftw.h>POPIS / INSTRUKCE
The ftw() function shall recursively descend the directory hierarchy rooted in path. For each object in the hierarchy, ftw() shall call the function pointed to by fn, passing it a pointer to a null-terminated character string containing the name of the object, a pointer to a stat structure containing information about the object, and an integer. Possible values of the integer, defined in the <ftw.h> header, are:- FTW_D
- For a directory.
- FTW_DNR
- For a directory that cannot be read.
- FTW_F
- For a file.
- FTW_SL
- For a symbolic link (but see also FTW_NS below).
- FTW_NS
- For an object other than a symbolic link on which
stat() could not successfully be executed. If the object is a
symbolic link and stat() failed, it is unspecified whether
ftw() passes FTW_SL or FTW_NS to the user-supplied function.
NÁVRATOVÁ HODNOTA
If the tree is exhausted, ftw() shall return 0. If the function pointed to by fn returns a non-zero value, ftw() shall stop its tree traversal and return whatever value was returned by the function pointed to by fn. If ftw() detects an error, it shall return -1 and set errno to indicate the error. If ftw() encounters an error other than [EACCES] (see FTW_DNR and FTW_NS above), it shall return -1 and set errno to indicate the error. The external variable errno may contain any error value that is possible when a directory is opened or when one of the stat functions is executed on a directory or file.CHYBY / ERRORY
The ftw() function shall fail if:- EACCES
- Search permission is denied for any component of path or read permission is denied for path.
- ELOOP
- A loop exists in symbolic links encountered during resolution of the path argument.
- ENAMETOOLONG
- The length of the path argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.
- ENOENT
- A component of path does not name an existing file or path is an empty string.
- ENOTDIR
- A component of path is not a directory.
- EOVERFLOW
- A field in the stat structure cannot be represented
correctly in the current programming environment for one or more files
found in the file hierarchy.
- EINVAL
- The value of the ndirs argument is invalid.
- ELOOP
- More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the path argument.
- ENAMETOOLONG
- Pathname resolution of a symbolic link produced an
intermediate result whose length exceeds {PATH_MAX}.
PŘÍKLADY POUŽITÍ
Walking a Directory Structure
The following example walks the current directory structure, calling the fn function for every directory entry, using at most 10 file descriptors:
#include <ftw.h>
...
if (ftw(".", fn, 10) != 0) {
perror("ftw"); exit(2);
}
APPLICATION USAGE
The ftw() function may allocate dynamic storage during its operation. If ftw() is forcibly terminated, such as by longjmp() or siglongjmp() being executed by the function pointed to by fn or an interrupt routine, ftw() does not have a chance to free that storage, so it remains permanently allocated. A safe way to handle interrupts is to store the fact that an interrupt has occurred, and arrange to have the function pointed to by fn return a non-zero value at its next invocation.RATIONALE
None.FUTURE DIRECTIONS
None.SOUVISEJÍCÍ
longjmp() , lstat() , malloc() , nftw() , opendir() , siglongjmp() , stat() , the Base Definitions volume of IEEE Std 1003.1-2001, <ftw.h>, <sys/stat.h>COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .| 2003 | IEEE/The Open Group |