Manual Pages for UNIX Darwin command on man fts
MyWebUniversity

Manual Pages for UNIX Darwin command on man fts

FTS(3) BSD Library Functions Manual FTS(3)

NAME

ffttss - traverse a file hierarchy

LLIIBBRRAARRYY

Standard C Library (libc, -lc)

SYNOPSIS

##iinncclluuddee <>

##iinncclluuddee <>

##iinncclluuddee <>

FTS * ffttssooppeenn(char * const *pathargv, int options, int (*compar)(const FTSENT **, const FTSENT **)); FTSENT *

ffttssrreeaadd(FTS *ftsp);

FTSENT *

ffttsscchhiillddrreenn(FTS *ftsp, int options);

int

ffttsssseett(FTS *ftsp, FTSENT *f, int options);

int

ffttsscclloossee(FTS *ftsp);

DESCRIPTION

The ffttss functions are provided for traversing UNIX file hierarchies. A simple overview is that the ffttssooppeenn() function returns a ``handle'' on a file hierarchy, which is then supplied to the other ffttss functions. The function ffttssrreeaadd() returns a pointer to a structure describing one of the files in the file hierarchy. The function ffttsscchhiillddrreenn() returns a pointer to a linked list of structures, each of which describes one of

the files contained in a directory in the hierarchy. In general, direc-

tories are visited two distinguishable times; in pre-order (before any of

their descendants are visited) and in post-order (after all of their

descendants have been visited). Files are visited once. It is possible

to walk the hierarchy ``logically'' (ignoring symbolic links) or physi-

cally (visiting symbolic links), order the walk of the hierarchy or prune

and/or re-visit portions of the hierarchy.

Two structures are defined (and typedef'd) in the include file .

The first is FTS, the structure that represents the file hierarchy itself. The second is FTSENT, the structure that represents a file in the file hierarchy. Normally, an FTSENT structure is returned for every file in the file hierarchy. In this manual page, ``file'' and ``FTSENT structure'' are generally interchangeable. The FTSENT structure contains at least the following fields, which are described in greater detail below:

typedef struct ftsent {

ushort ftsinfo; /* flags for FTSENT structure */

char *ftsaccpath; /* access path */

char *ftspath; /* root path */

ushort ftspathlen; /* strlen(ftspath) */

char *ftsname; /* file name */

ushort ftsnamelen; /* strlen(ftsname) */

short ftslevel; /* depth (-1 to N) */

int ftserrno; /* file errno */

long ftsnumber; /* local numeric value */

void *ftspointer; /* local address value */

struct ftsent *ftsparent; /* parent directory */

struct ftsent *ftslink; /* next file structure */

struct ftsent *ftscycle; /* cycle structure */

struct stat *ftsstatp; /* stat(2) information */

} FTSENT; These fields are defined as follows:

ftsinfo One of the following values describing the returned FTSENT

structure and the file it represents. With the exception of directories without errors (FTSD), all of these entries are terminal, that is, they will not be revisited, nor will any of their descendants be visited.

FTSD A directory being visited in pre-order.

FTSDC A directory that causes a cycle in the tree.

(The ftscycle field of the FTSENT structure

will be filled in as well.) FTSDEFAULT Any FTSENT structure that represents a file type not explicitly described by one of the

other ftsinfo values.

FTSDNR A directory which cannot be read. This is an

error return, and the ftserrno field will be

set to indicate what caused the error.

FTSDOT A file named `.' or `..' which was not speci-

fied as a file name to ffttssooppeenn() (see FTSSEEDOT).

FTSDP A directory being visited in post-order. The

contents of the FTSENT structure will be

unchanged from when it was returned in pre-

order, i.e. with the ftsinfo field set to

FTSD.

FTSERR This is an error return, and the ftserrno

field will be set to indicate what caused the error. FTSF A regular file. FTSNS A file for which no stat(2) information was

available. The contents of the ftsstatp field

are undefined. This is an error return, and

the ftserrno field will be set to indicate

what caused the error. FTSNSOK A file for which no stat(2) information was

requested. The contents of the ftsstatp field

are undefined. FTSSL A symbolic link.

FTSSLNONE A symbolic link with a non-existent target.

The contents of the ftsstatp field reference

the file characteristic information for the symbolic link itself.

ftsaccpath A path for accessing the file from the current directory.

ftspath The path for the file relative to the root of the traversal.

This path contains the path specified to ffttssooppeenn() as a prefix.

ftspathlen The length of the string referenced by ftspath.

ftsname The name of the file.

ftsnamelen The length of the string referenced by ftsname.

ftslevel The depth of the traversal, numbered from -1 to N, where

this file was found. The FTSENT structure representing the parent of the starting point (or root) of the traversal is

numbered FTSROOTPARENTLEVEL (-1), and the FTSENT structure

for the root itself is numbered FTSROOTLEVEL (0).

ftserrno Upon return of a FTSENT structure from the ffttsscchhiillddrreenn() or

ffttssrreeaadd() functions, with its ftsinfo field set to

FTSDNR, FTSERR or FTSNS, the ftserrno field contains the

value of the external variable errno specifying the cause of

the error. Otherwise, the contents of the ftserrno field

are undefined.

ftsnumber This field is provided for the use of the application pro-

gram and is not modified by the ffttss functions. It is ini-

tialized to 0.

ftspointer This field is provided for the use of the application pro-

gram and is not modified by the ffttss functions. It is ini-

tialized to NULL.

ftsparent A pointer to the FTSENT structure referencing the file in

the hierarchy immediately above the current file, i.e. the

directory of which this file is a member. A parent struc-

ture for the initial entry point is provided as well, how-

ever, only the ftslevel, ftsnumber and ftspointer fields

are guaranteed to be initialized.

ftslink Upon return from the ffttsscchhiillddrreenn() function, the ftslink

field points to the next structure in the NULL-terminated

linked list of directory members. Otherwise, the contents

of the ftslink field are undefined.

ftscycle If a directory causes a cycle in the hierarchy (see FTSDC),

either because of a hard link between two directories, or a

symbolic link pointing to a directory, the ftscycle field

of the structure will point to the FTSENT structure in the hierarchy that references the same file as the current

FTSENT structure. Otherwise, the contents of the ftscycle

field are undefined.

ftsstatp A pointer to stat(2) information for the file.

A single buffer is used for all of the paths of all of the files in the

file hierarchy. Therefore, the ftspath and ftsaccpath fields are guar-

anteed to be NUL-terminated only for the file most recently returned by

ffttssrreeaadd(). To use these fields to reference any files represented by other FTSENT structures will require that the path buffer be modified

using the information contained in that FTSENT structure's ftspathlen

field. Any such modifications should be undone before further calls to

ffttssrreeaadd() are attempted. The ftsname field is always NUL-terminated.

FFTTSSOOPPEENN The ffttssooppeenn() function takes a pointer to an array of character pointers naming one or more paths which make up a logical file hierarchy to be traversed. The array must be terminated by a NULL pointer. There are a number of options, at least one of which (either FTSLOGICAL or FTSPHYSICAL) must be specified. The options are selected by or'ing the following values: FTSCOMFOLLOW This option causes any symbolic link specified as a root path to be followed immediately whether or not FTSLOGICAL is also specified.

FTSLOGICAL This option causes the ffttss routines to return FTSENT struc-

tures for the targets of symbolic links instead of the sym-

bolic links themselves. If this option is set, the only symbolic links for which FTSENT structures are returned to

the application are those referencing non-existent files.

Either FTSLOGICAL or FTSPHYSICAL must be provided to the ffttssooppeenn() function. FTSNOCHDIR As a performance optimization, the ffttss functions change directories as they walk the file hierarchy. This has the

side-effect that an application cannot rely on being in any

particular directory during the traversal. The FTSNOCHDIR option turns off this optimization, and the ffttss functions

will not change the current directory. Note that applica-

tions should not themselves change their current directory and try to access files unless FTSNOCHDIR is specified and absolute pathnames were provided as arguments to ffttssooppeenn().

FTSNOSTAT By default, returned FTSENT structures reference file char-

acteristic information (the statp field) for each file vis-

ited. This option relaxes that requirement as a perfor-

mance optimization, allowing the ffttss functions to set the

ftsinfo field to FTSNSOK and leave the contents of the

statp field undefined.

FTSPHYSICAL This option causes the ffttss routines to return FTSENT struc-

tures for symbolic links themselves instead of the target

files they point to. If this option is set, FTSENT struc-

tures for all symbolic links in the hierarchy are returned to the application. Either FTSLOGICAL or FTSPHYSICAL must be provided to the ffttssooppeenn() function. FTSSEEDOT By default, unless they are specified as path arguments to ffttssooppeenn(), any files named `.' or `..' encountered in the file hierarchy are ignored. This option causes the ffttss routines to return FTSENT structures for them. FTSXDEV This option prevents ffttss from descending into directories that have a different device number than the file from which the descent began.

The argument ccoommppaarr() specifies a user-defined function which may be used

to order the traversal of the hierarchy. It takes two pointers to point-

ers to FTSENT structures as arguments and should return a negative value, zero, or a positive value to indicate if the file referenced by its first argument comes before, in any order with respect to, or after, the file

referenced by its second argument. The ftsaccpath, ftspath and

ftspathlen fields of the FTSENT structures may never be used in this

comparison. If the ftsinfo field is set to FTSNS or FTSNSOK, the

ftsstatp field may not either. If the ccoommppaarr() argument is NULL, the

directory traversal order is in the order listed in pathargv for the root paths, and in the order listed in the directory for everything else. FFTTSSRREEAADD

The ffttssrreeaadd() function returns a pointer to an FTSENT structure describ-

ing a file in the hierarchy. Directories (that are readable and do not

cause cycles) are visited at least twice, once in pre-order and once in

post-order. All other files are visited at least once. (Hard links

between directories that do not cause cycles or symbolic links to sym-

bolic links may cause files to be visited more than once, or directories more than twice.) If all the members of the hierarchy have been returned, ffttssrreeaadd() returns NULL and sets the external variable errno to 0. If an error unrelated to a file in the hierarchy occurs, ffttssrreeaadd() returns NULL and sets errno appropriately. If an error related to a returned file occurs, a pointer to an FTSENT structure is returned, and errno may or may not

have been set (see ftsinfo).

The FTSENT structures returned by ffttssrreeaadd() may be overwritten after a call to ffttsscclloossee() on the same file hierarchy stream, or, after a call to ffttssrreeaadd() on the same file hierarchy stream unless they represent a file of type directory, in which case they will not be overwritten until after a call to ffttssrreeaadd() after the FTSENT structure has been returned

by the function ffttssrreeaadd() in post-order.

FFTTSSCCHHIILLDDRREENN The ffttsscchhiillddrreenn() function returns a pointer to an FTSENT structure

describing the first entry in a NULL-terminated linked list of the files

in the directory represented by the FTSENT structure most recently

returned by ffttssrreeaadd(). The list is linked through the ftslink field of

the FTSENT structure, and is ordered by the user-specified comparison

function, if any. Repeated calls to ffttsscchhiillddrreenn() will recreate this linked list. As a special case, if ffttssrreeaadd() has not yet been called for a hierarchy,

ffttsscchhiillddrreenn() will return a pointer to the files in the logical direc-

tory specified to ffttssooppeenn(), i.e. the arguments specified to ffttssooppeenn(). Otherwise, if the FTSENT structure most recently returned by ffttssrreeaadd()

is not a directory being visited in pre-order, or the directory does not

contain any files, ffttsscchhiillddrreenn() returns NULL and sets errno to zero.

If an error occurs, ffttsscchhiillddrreenn() returns NULL and sets errno appropri-

ately. The FTSENT structures returned by ffttsscchhiillddrreenn() may be overwritten after a call to ffttsscchhiillddrreenn(), ffttsscclloossee() or ffttssrreeaadd() on the same file hierarchy stream. Option may be set to the following value:

FTSNAMEONLY Only the names of the files are needed. The contents of

all the fields in the returned linked list of structures

are undefined with the exception of the ftsname and

ftsnamelen fields.

FFTTSSSSEETT The function ffttsssseett() allows the user application to determine further

processing for the file f of the stream ftsp. The ffttsssseett() function

returns 0 on success, and -1 if an error occurs. Option must be set to

one of the following values:

FTSAGAIN Re-visit the file; any file type may be re-visited. The

next call to ffttssrreeaadd() will return the referenced file.

The ftsstat and ftsinfo fields of the structure will be

reinitialized at that time, but no other fields will have been changed. This option is meaningful only for the most recently returned file from ffttssrreeaadd(). Normal use is for

post-order directory visits, where it causes the directory

to be re-visited (in both pre and post-order) as well as

all of its descendants.

FTSFOLLOW The referenced file must be a symbolic link. If the refer-

enced file is the one most recently returned by ffttssrreeaadd(), the next call to ffttssrreeaadd() returns the file with the

ftsinfo and ftsstatp fields reinitialized to reflect the

target of the symbolic link instead of the symbolic link itself. If the file is one of those most recently returned

by ffttsscchhiillddrreenn(), the ftsinfo and ftsstatp fields of the

structure, when returned by ffttssrreeaadd(), will reflect the target of the symbolic link instead of the symbolic link itself. In either case, if the target of the symbolic link does not exist the fields of the returned structure will be

unchanged and the ftsinfo field will be set to FTSSLNONE.

If the target of the link is a directory, the pre-order

return, followed by the return of all of its descendants,

followed by a post-order return, is done.

FTSSKIP No descendants of this file are visited. The file may be one of those most recently returned by either ffttsscchhiillddrreenn() or ffttssrreeaadd(). FFTTSSCCLLOOSSEE

The ffttsscclloossee() function closes a file hierarchy stream ftsp and restores

the current directory to the directory from which ffttssooppeenn() was called

to open ftsp. The ffttsscclloossee() function returns 0 on success, and -1 if

an error occurs. EERRRROORRSS The function ffttssooppeenn() may fail and set errno for any of the errors specified for the library functions open(2) and malloc(3). The function ffttsscclloossee() may fail and set errno for any of the errors specified for the library functions chdir(2) and close(2). The functions ffttssrreeaadd() and ffttsscchhiillddrreenn() may fail and set errno for any of the errors specified for the library functions chdir(2), malloc(3), opendir(3), readdir(3) and stat(2). In addition, ffttsscchhiillddrreenn(), ffttssooppeenn() and ffttsssseett() may fail and set errno as follows: [EINVAL] The options were invalid.

SEE ALSO

find(1), chdir(2), stat(2), qsort(3) STANDARDS The ffttss utility is expected to be included in a future IEEE Std

1003.1-1988 (``POSIX.1'') revision.

BSD April 16, 1994 BSD




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™