home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
bbs
/
gnu
/
ixemul-39.47-env-bin.lha
/
man
/
cat3
/
fts.0
< prev
next >
Wrap
Text File
|
1993-12-07
|
22KB
|
397 lines
FTS(3) UNIX Programmer's Manual FTS(3)
NNAAMMEE
ffttss - traverse a file hierarchy
SSYYNNOOPPSSIISS
##iinncclluuddee <<ssyyss//ttyyppeess..hh>>
##iinncclluuddee <<ssyyss//ssttaatt..hh>>
##iinncclluuddee <<ffttss..hh>>
_F_T_S _*
ffttss__ooppeenn(_c_h_a_r _* _c_o_n_s_t _*_p_a_t_h___a_r_g_v, _i_n_t _o_p_t_i_o_n_s,
_i_n_t _*_c_o_m_p_a_r_(_c_o_n_s_t _F_T_S_E_N_T _*_, _c_o_n_s_t _F_T_S_E_N_T _*_))
_F_T_S_E_N_T _*
ffttss__rreeaadd(_F_T_S _*_f_t_s_p)
_F_T_S_E_N_T _*
ffttss__cchhiillddrreenn(_F_T_S _*_f_t_s_p)
_i_n_t
ffttss__sseett(_F_T_S _f_t_s_p, _F_T_S_E_N_T _*_f, _i_n_t _o_p_t_i_o_n_s)
_i_n_t
ffttss__cclloossee(_F_T_S _*_f_t_s_p)
DDEESSCCRRIIPPTTIIOONN
The ffttss functions are provided for traversing UNIX file hierarchies.
The simple overview is that the ffttss__ooppeenn() function returns a ``handle''
on a file hierarchy, which is supplied to the other ffttss functions to de
termine which hierarchy they operate on. The function ffttss__rreeaadd() returns
a pointer to a structure describing one of the files in the file hierar
chy. The function ffttss__cchhiillddrreenn() returns a pointer to a linked list of
structures, each of which describes one of the files contained in a di
rectory in the hierarchy. In general, directories are visited two dis
tinguishable times; in preorder (before any of their descendants are
visited) and in postorder (after all of their descendants have been vis
ited). Files are visited once. It is possible to walk the hierarchy
``logically'' (ignoring symbolic links) or physically (visiting symbolic
links), order the walk of the hierarchy or prune and/or revisit portions
of the hierarchy.
Two structures are defined (and typedef'd) in the include file <_f_t_s_._h>.
The first is _F_T_S, the structure that represents the file hierarchy
stream. The second is _F_T_S_E_N_T, the structure that represents a file in
the file hierarchy. Normally, an _F_T_S_E_N_T structure is returned for every
file in the file hierarchy. In this manual page, ``file'' and ``_F_T_S_E_N_T
structure'' are generally interchangeable. The _F_T_S_E_N_T structure contains
at least the following fields, which are described in greater detail be
low:
typedef struct _ftsent {
u_short fts_info; /* flags for FTSENT structure */
char *fts_accpath; /* access path */
char *fts_path; /* root path */
short fts_pathlen; /* strlen(fts_path) */
char *fts_name; /* file name */
short fts_namelen; /* strlen(fts_name) */
short fts_level; /* depth (-1 to N) */
long fts_number; /* local numeric value */
void *fts_pointer; /* local address value */
struct ftsent *fts_parent; /* parent directory */
struct ftsent *fts_link; /* cycle or next file structure */
struct stat fts_statb; /* stat(2) information */
} FTSENT;
These fields are defined as follows:
_f_t_s___i_n_f_o One of the following flags describing the returned _F_T_S_E_N_T
structure and the file it represents. With the exception of
directories without errors (FTS_D), all of these entries are
terminal, that is, they will not be revisited, nor will any
of their descendants be visited.
FTS_D A directory being visited in preorder.
FTS_DC A directory that causes a cycle in the tree.
(The _f_t_s___l_i_n_k field of the _F_T_S_E_N_T structure
will be filled in as well.)
FTS_DEFAULT Any _F_T_S_E_N_T structure that represents a file
type not explicitly described by one of the
other _f_t_s___i_n_f_o values.
FTS_DNR A directory which cannot be read. An error re
turn; the external variable _e_r_r_n_o will be set
to indicate the error.
FTS_DOT A file named `.' or `..' which was not speci
fied as a file name to ffttss__ooppeenn() (see
FTS_SEEDOT).
FTS_DP A directory being visited in postorder. The
contents of the _F_T_S_E_N_T structure will be un
changed from when it was returned in preorder,
i.e. with the _f_t_s___i_n_f_o field set to FTS_D.
FTS_ERR An error return; the external variable _e_r_r_n_o
will be set to indicate the error.
FTS_F A regular file.
FTS_NS A file for which no stat(2) information was
available. The contents of the _f_t_s___s_t_a_t_b field
are undefined. An error return; the external
variable _e_r_r_n_o will be set to indicate the er
ror.
FTS_NSOK A file for which no stat(2) information was re
quested. The contents of the _f_t_s___s_t_a_t_b field
are undefined.
FTS_SL A symbolic link.
FTS_SLNONE A symbolic link with a nonexistent target.
The contents of the _f_t_s___s_t_a_t_b field contain the
file characteristic information for the symbol
ic link itself.
_f_t_s___a_c_c_p_a_t_h A path for accessing the file from the current directory.
_f_t_s___p_a_t_h The path for the file relative to the root of the traversal.
This path contains the path specified to ffttss__ooppeenn() as a
prefix.
_f_t_s___p_a_t_h_l_e_n The length of the string referenced by _f_t_s___p_a_t_h.
_f_t_s___n_a_m_e The name of the file.
_f_t_s___n_a_m_e_l_e_n The length of the string referenced by _f_t_s___n_a_m_e.
_f_t_s___l_e_v_e_l The depth of the traversal, numbered from -1 to N, where
this file was found. The _F_T_S_E_N_T structure representing the
parent of the starting point (or root) of the traversal is
numbered -1, and the _F_T_S_E_N_T structure for the root itself is
numbered 0.
_f_t_s___n_u_m_b_e_r 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. The fields _f_t_s___n_u_m_b_e_r and _f_t_s___p_o_i_n_t_e_r occupy
the same physical location; using both may cause undefined
results.
_f_t_s___p_o_i_n_t_e_r 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. The fields _f_t_s___n_u_m_b_e_r and _f_t_s___p_o_i_n_t_e_r