home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / ixemul-39.47-env-bin.lha / man / cat3 / fts.0 < prev    next >
Text File  |  1993-12-07  |  22KB  |  397 lines

  1.  
  2. FTS(3)                     UNIX Programmer's Manual                     FTS(3)
  3.  
  4. NNAAMMEE
  5.      ffttss - traverse a file hierarchy
  6.  
  7. SSYYNNOOPPSSIISS
  8.      ##iinncclluuddee <<ssyyss//ttyyppeess..hh>>
  9.      ##iinncclluuddee <<ssyyss//ssttaatt..hh>>
  10.      ##iinncclluuddee <<ffttss..hh>>
  11.  
  12.      _F_T_S _*
  13.      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,
  14.              _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 _*_))
  15.  
  16.      _F_T_S_E_N_T _*
  17.      ffttss__rreeaadd(_F_T_S _*_f_t_s_p)
  18.  
  19.      _F_T_S_E_N_T _*
  20.      ffttss__cchhiillddrreenn(_F_T_S _*_f_t_s_p)
  21.  
  22.      _i_n_t
  23.      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)
  24.  
  25.      _i_n_t
  26.      ffttss__cclloossee(_F_T_S _*_f_t_s_p)
  27.  
  28. DDEESSCCRRIIPPTTIIOONN
  29.      The ffttss functions are provided for traversing UNIX file hierarchies.
  30.  
  31.      The simple overview is that the ffttss__ooppeenn() function returns a ``handle''
  32.      on a file hierarchy, which is supplied to the other ffttss functions to de­
  33.      termine which hierarchy they operate on.  The function ffttss__rreeaadd() returns
  34.      a pointer to a structure describing one of the files in the file hierar­
  35.      chy.  The function ffttss__cchhiillddrreenn() returns a pointer to a linked list of
  36.      structures, each of which describes one of the files contained in a di­
  37.      rectory in the hierarchy.  In general, directories are visited two dis­
  38.      tinguishable times; in pre­order (before any of their descendants are
  39.      visited) and in post­order (after all of their descendants have been vis­
  40.      ited).  Files are visited once.  It is possible to walk the hierarchy
  41.      ``logically'' (ignoring symbolic links) or physically (visiting symbolic
  42.      links), order the walk of the hierarchy or prune and/or re­visit portions
  43.      of the hierarchy.
  44.  
  45.      Two structures are defined (and typedef'd) in the include file <_f_t_s_._h>.
  46.      The first is _F_T_S, the structure that represents the file hierarchy
  47.      stream.  The second is _F_T_S_E_N_T, the structure that represents a file in
  48.      the file hierarchy.  Normally, an _F_T_S_E_N_T structure is returned for every
  49.      file in the file hierarchy.  In this manual page, ``file'' and ``_F_T_S_E_N_T
  50.      structure'' are generally interchangeable.  The _F_T_S_E_N_T structure contains
  51.      at least the following fields, which are described in greater detail be­
  52.      low:
  53.  
  54.      typedef struct _ftsent {
  55.              u_short fts_info;               /* flags for FTSENT structure */
  56.              char *fts_accpath;              /* access path */
  57.              char *fts_path;                 /* root path */
  58.              short fts_pathlen;              /* strlen(fts_path) */
  59.              char *fts_name;                 /* file name */
  60.              short fts_namelen;              /* strlen(fts_name) */
  61.              short fts_level;                /* depth (-1 to N) */
  62.              long fts_number;                /* local numeric value */
  63.              void *fts_pointer;              /* local address value */
  64.              struct ftsent *fts_parent;      /* parent directory */
  65.              struct ftsent *fts_link;        /* cycle or next file structure */
  66.              struct stat fts_statb;          /* stat(2) information */
  67.      } FTSENT;
  68.  
  69.      These fields are defined as follows:
  70.  
  71.      _f_t_s___i_n_f_o     One of the following flags describing the returned _F_T_S_E_N_T
  72.                   structure and the file it represents.  With the exception of
  73.                   directories without errors (FTS_D), all of these entries are
  74.                   terminal, that is, they will not be revisited, nor will any
  75.                   of their descendants be visited.
  76.  
  77.                   FTS_D        A directory being visited in pre­order.
  78.  
  79.                   FTS_DC       A directory that causes a cycle in the tree.
  80.                                (The _f_t_s___l_i_n_k field of the _F_T_S_E_N_T structure
  81.                                will be filled in as well.)
  82.  
  83.                   FTS_DEFAULT  Any _F_T_S_E_N_T structure that represents a file
  84.                                type not explicitly described by one of the
  85.                                other _f_t_s___i_n_f_o values.
  86.  
  87.                   FTS_DNR      A directory which cannot be read.  An error re­
  88.                                turn; the external variable _e_r_r_n_o will be set
  89.                                to indicate the error.
  90.  
  91.                   FTS_DOT      A file named `.' or `..' which was not speci­
  92.                                fied as a file name to ffttss__ooppeenn() (see
  93.                                FTS_SEEDOT).
  94.  
  95.                   FTS_DP       A directory being visited in post­order.  The
  96.                                contents of the _F_T_S_E_N_T structure will be un­
  97.                                changed from when it was returned in pre­order,
  98.                                i.e. with the _f_t_s___i_n_f_o field set to FTS_D.
  99.  
  100.                   FTS_ERR      An error return; the external variable _e_r_r_n_o
  101.                                will be set to indicate the error.
  102.  
  103.                   FTS_F        A regular file.
  104.  
  105.                   FTS_NS       A file for which no stat(2) information was
  106.                                available.  The contents of the _f_t_s___s_t_a_t_b field
  107.                                are undefined.  An error return; the external
  108.                                variable _e_r_r_n_o will be set to indicate the er­
  109.                                ror.
  110.  
  111.                   FTS_NSOK     A file for which no stat(2) information was re­
  112.                                quested.  The contents of the _f_t_s___s_t_a_t_b field
  113.                                are undefined.
  114.  
  115.                   FTS_SL       A symbolic link.
  116.  
  117.                   FTS_SLNONE   A symbolic link with a non­existent target.
  118.                                The contents of the _f_t_s___s_t_a_t_b field contain the
  119.                                file characteristic information for the symbol­
  120.                                ic link itself.
  121.  
  122.      _f_t_s___a_c_c_p_a_t_h  A path for accessing the file from the current directory.
  123.  
  124.      _f_t_s___p_a_t_h     The path for the file relative to the root of the traversal.
  125.                   This path contains the path specified to ffttss__ooppeenn() as a
  126.                   prefix.
  127.  
  128.      _f_t_s___p_a_t_h_l_e_n  The length of the string referenced by _f_t_s___p_a_t_h.
  129.  
  130.  
  131.  
  132.      _f_t_s___n_a_m_e     The name of the file.
  133.  
  134.      _f_t_s___n_a_m_e_l_e_n  The length of the string referenced by _f_t_s___n_a_m_e.
  135.  
  136.      _f_t_s___l_e_v_e_l    The depth of the traversal, numbered from -1 to N, where
  137.                   this file was found.  The _F_T_S_E_N_T structure representing the
  138.                   parent of the starting point (or root) of the traversal is
  139.                   numbered -1, and the _F_T_S_E_N_T structure for the root itself is
  140.                   numbered 0.
  141.  
  142.      _f_t_s___n_u_m_b_e_r   This field is provided for the use of the application pro­
  143.                   gram and is not modified by the ffttss functions.  It is ini­
  144.                   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
  145.                   the same physical location; using both may cause undefined
  146.                   results.
  147.  
  148.      _f_t_s___p_o_i_n_t_e_r  This field is provided for the use of the application pro­
  149.                   gram and is not modified by the ffttss functions.  It is ini­
  150.                   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 oc­
  151.                   cupy the same physical location; using both may cause unde­
  152.                   fined results.
  153.  
  154.      _f_t_s___p_a_r_e_n_t   A pointer to the _F_T_S_E_N_T structure referencing the file in
  155.                   the hierarchy immediately above the current file, i.e. the
  156.                   directory of which this file is a member.  A parent struc­
  157.                   ture for the initial entry point is provided as well, howev­
  158.                   er, only the _f_t_s___l_e_v_e_l, _f_t_s___n_u_m_b_e_r and _f_t_s___p_o_i_n_t_e_r fields
  159.                   are guaranteed to be initialized.
  160.  
  161.      _f_t_s___l_i_n_k     The _f_t_s___l_i_n_k field has two separate uses.  If a directory
  162.                   causes a cycle in the hierarchy (see FTS_DC), either because
  163.                   of a hard link between two directories, or a symbolic link
  164.                   pointing to a directory, the _f_t_s___l_i_n_k field of the structure
  165.                   will point to the _F_T_S_E_N_T structure in the hierarchy that
  166.                   references the same file as the current _F_T_S_E_N_T structure.
  167.                   Also, upon return from the ffttss__cchhiillddrreenn() function, the
  168.                   _f_t_s___l_i_n_k field points to the next structure in the linked
  169.                   list of directory members.  Otherwise, the contents of the
  170.                   _f_t_s___l_i_n_k field are undefined.
  171.  
  172.      _f_t_s___s_t_a_t_b    Stat(2) information for the file.
  173.  
  174. FFTTSS__OOPPEENN
  175.      The ffttss__ooppeenn() function takes a pointer to an array of character pointers
  176.      naming one or more paths which make up a logical file hierarchy to be
  177.      traversed.  The array must be terminated by a NULL pointer.
  178.  
  179.      There are a number of options, at least one of which (either FTS_LOGICAL
  180.      or FTS_PHYSICAL) must be specified.  The options are selected by _o_r'ing
  181.      the following values:
  182.  
  183.      FTS_LOGICAL   This option causes the ffttss routines to return _F_T_S_E_N_T struc­
  184.                    tures for the targets of symbolic links instead of the sym­
  185.                    bolic links themselves.  If this option is set, the only
  186.                    symbolic links for which _F_T_S_E_N_T structures are returned to
  187.                    the application are those referencing non­existent files.
  188.                    Either FTS_LOGICAL or FTS_PHYSICAL _m_u_s_t be provided to the
  189.                    ffttss__ooppeenn() function.
  190.  
  191.      FTS_NOCHDIR   As a performance optimization, the ffttss functions change di­
  192.                    rectories as they walk the file hierarchy.  This has the
  193.                    side­effect that an application cannot rely on being in any
  194.                    particular directory during the traversal.  The FTS_NOCHDIR
  195.                    option turns off this optimization, and the ffttss functions
  196.                    will not change the current directory.  Note that applica­
  197.                    tions should not themselves change their current directory
  198.                    and try to access files unless FTS_NOCHDIR is specified and
  199.                    absolute pathnames were provided as arguments to
  200.                    ffttss__ooppeenn().
  201.  
  202.      FTS_NOSTAT    By default, returned _F_T_S_E_N_T structures contain file charac­
  203.                    teristic information (the _s_t_a_t_b field) for each file visit­
  204.                    ed.  This option relaxes that requirement as a performance
  205.                    optimization, allowing the ffttss functions to set the
  206.                    _f_t_s___i_n_f_o field to FTS_NSOK and leave the contents of the
  207.                    _s_t_a_t_b field undefined.
  208.  
  209.      FTS_PHYSICAL  This option causes the ffttss routines to return _F_T_S_E_N_T struc­
  210.                    tures for symbolic links themselves instead of the target
  211.                    files they point to.  If this option is set, _F_T_S_E_N_T struc­
  212.                    tures for all symbolic links in the hierarchy are returned
  213.                    to the application.  Either FTS_LOGICAL or FTS_PHYSICAL
  214.                    _m_u_s_t be provided to the ffttss__ooppeenn() function.
  215.  
  216.      FTS_SEEDOT    By default, unless they are specified as path arguments to
  217.                    ffttss__ooppeenn(), any files named `.' and `..' encountered in the
  218.                    file hierarchy are ignored.  This option causes the ffttss
  219.                    routines to return _F_T_S_E_N_T structures for them.
  220.  
  221.      FTS_XDEV      This option prevents ffttss from descending into directories
  222.                    that have a different device number than the file from
  223.                    which the descent began.
  224.  
  225.      The argument ccoommppaarr() specifies a user­defined function which may be used
  226.      to order the traversal of the hierarchy.  It takes two pointers to point­
  227.      ers to _F_T_S_E_N_T structures as arguments and should return a negative value,
  228.      zero, or a positive value to indicate if the file referenced by its first
  229.      argument comes before, in any order with respect to, or after, the file
  230.      referenced by its second argument.  The _f_t_s___a_c_c_p_a_t_h, _f_t_s___p_a_t_h and
  231.      _f_t_s___p_a_t_h_l_e_n fields of the _F_T_S_E_N_T structures may _n_e_v_e_r be used in this
  232.      comparison.  If the _f_t_s___i_n_f_o field is set to FTS_NS or the _f_t_s___s_t_a_b field
  233.      may not either.  If the ccoommppaarr() argument is NULL, the directory traver­
  234.      sal order is unspecified except for the root paths which are traversed in
  235.      the order listed in _p_a_t_h___a_r_g_v.
  236.  
  237. FFTTSS__RREEAADD
  238.      The ffttss__rreeaadd() function returns a pointer to an _F_T_S_E_N_T structure describ­
  239.      ing a file in the hierarchy.  Directories (that are readable and do not
  240.      cause cycles) are visited at least twice, once in pre­order and once in
  241.      post­order.  All other files are visited at least once.  (Hard links be­
  242.      tween directories that do not cause cycles or symbolic links to symbolic
  243.      links may cause files to be visited more than once, or directories more
  244.      than twice.)
  245.  
  246.      If all the members of the hierarchy have been returned, ffttss__rreeaadd() re­
  247.      turns NULL and sets the external variable _e_r_r_n_o to 0.  If an error unre­
  248.      lated to a file in the hierarchy occurs, ffttss__rreeaadd() returns NULL and sets
  249.      _e_r_r_n_o appropriately.  If an error related to a returned file occurs, a
  250.      pointer to an _F_T_S_E_N_T structure is returned, and _e_r_r_n_o may or may not have
  251.      been set (see _f_t_s___i_n_f_o).
  252.  
  253.      The _F_T_S_E_N_T structures returned by ffttss__rreeaadd() may be overwritten after a
  254.      call to ffttss__cclloossee() on the same file hierarchy stream, or, after a call
  255.      to ffttss__rreeaadd() on the same file hierarchy stream unless they represent a
  256.      file of type directory, in which case they will not be overwritten until
  257.      after a call to ffttss__rreeaadd() after the _F_T_S_E_N_T structure has been returned
  258.      by the function ffttss__rreeaadd() in post­order.
  259.  
  260. FFTTSS__CCHHIILLDDRREENN
  261.      The ffttss__cchhiillddrreenn() function returns a pointer to an _F_T_S_E_N_T structure de­
  262.      scribing the first entry in a linked list of the files in the directory
  263.      represented by the _F_T_S_E_N_T structure most recently returned by ffttss__rreeaadd().
  264.      The list is linked through the _f_t_s___l_i_n_k field of the _F_T_S_E_N_T structure,
  265.      and is ordered by the user­specified comparison function, if any.  Re­
  266.      peated calls to ffttss__cchhiillddrreenn() will recreate this linked list.
  267.  
  268.      If the _F_T_S_E_N_T structure most recently returned by ffttss__rreeaadd() is not a di­
  269.      rectory being visited in pre­order, or the directory does not contain any
  270.      files, ffttss__cchhiillddrreenn() returns NULL and sets _e_r_r_n_o to zero.  If an error
  271.      occurs, ffttss__cchhiillddrreenn() returns NULL and sets _e_r_r_n_o appropriately.
  272.  
  273.      The _F_T_S_E_N_T structures returned by ffttss__cchhiillddrreenn() may be overwritten after
  274.      a call to ffttss__cclloossee() on the same file hierarchy stream, or after a call
  275.      to ffttss__cchhiillddrreenn() or ffttss__rreeaadd() on the same file hierarchy stream.
  276.  
  277.      A single buffer is used for all of the paths of all of the files in the
  278.      file hierarchy.  Therefore, the _f_t_s___p_a_t_h and _f_t_s___a_c_c_p_a_t_h fields are guar­
  279.      anteed to be NULL­terminated _o_n_l_y for the file most recently returned by
  280.      ffttss__rreeaadd().  To use these fields to reference any files represented by
  281.      other _F_T_S_E_N_T structures will require that the path buffer be modified us­
  282.      ing the information contained in that _F_T_S_E_N_T structure's _f_t_s___p_a_t_h_l_e_n
  283.      field.  Any such modifications should be undone before further calls to
  284.      ffttss__rreeaadd() are attempted.  The _f_t_s___n_a_m_e field is always NULL­terminated.
  285.  
  286. FFTTSS__SSEETT
  287.      The function ffttss__sseett() allows the user application to determine further
  288.      processing for the file _f of the stream _f_t_s_p. The ffttss__sseett() function re­
  289.      turns 0 on success, and -1 if an error occurs.  _O_p_t_i_o_n must be set to one
  290.      of the following values:
  291.  
  292.      FTS_AGAIN     Re­visit the file; any file type may be re­visited.  The
  293.                    next call to ffttss__rreeaadd() will return the referenced file.
  294.                    The _f_t_s___s_t_a_t and _f_t_s___i_n_f_o fields of the structure will be
  295.                    reinitialized at that time, but no other fields will have
  296.                    been changed.  This option is meaningful only for the most
  297.                    recently returned file from ffttss__rreeaadd().  Normal use is for
  298.                    post­order directory visits, where it causes the directory
  299.                    to be re­visited (in both pre and post­order) as well as
  300.                    all of its descendants.
  301.  
  302.      FTS_FOLLOW    The referenced file must be a symbolic link.  If the refer­
  303.                    enced file is the one most recently returned by ffttss__rreeaadd(),
  304.                    the next call to ffttss__rreeaadd() returns the file with the
  305.                    _f_t_s___i_n_f_o and _f_t_s___s_t_a_t_b fields reinitialized to reflect the
  306.                    target of the symbolic link instead of the symbolic link
  307.                    itself.  If the file is one of those most recently returned
  308.                    by ffttss__cchhiillddrreenn(), the _f_t_s___i_n_f_o and _f_t_s___s_t_a_t_b fields of the
  309.                    structure, when returned by ffttss__rreeaadd(), will reflect the
  310.                    target of the symbolic link instead of the symbolic link
  311.                    itself.  In either case, if the target of the symbolic link
  312.                    does not exist the fields of the returned structure will be
  313.                    unchanged and the _f_t_s___i_n_f_o field will be set to FTS_SLNONE.
  314.  
  315.                    If the target of the link is a directory, the pre­order re­
  316.                    turn, followed by the return of all of its descendants,
  317.                    followed by a post­order return, is done.
  318.  
  319.      FTS_SKIP      No descendants of this file are visited.  The file may be
  320.                    one of those most recently returned by either
  321.                    ffttss__cchhiillddrreenn() or ffttss__rreeaadd().
  322.  
  323. FFTTSS__CCLLOOSSEE
  324.      The ffttss__cclloossee() function closes a file hierarchy stream _f_t_s_p and restores
  325.      the current directory to the directory from which ffttss__ooppeenn() was called
  326.      to open _f_t_s_p. The ffttss__cclloossee() function returns 0 on success, and -1 if an
  327.      error occurs.
  328.  
  329. EERRRROORRSS
  330.      The function ffttss__ooppeenn() may fail and set errno for any of the errors
  331.      specified for the library functions open(2) and malloc(3).
  332.  
  333.      The function ffttss__cclloossee() may fail and set errno for any of the errors
  334.      specified for the library functions chdir(2) and close(2).
  335.  
  336.      The functions FFttss__rreeaadd() and ffttss__cchhiillddrreenn() may fail and set errno for
  337.      any of the errors specified for the library functions chdir(2),
  338.      malloc(3),  opendir(3),  readdir(3) and stat(2).
  339.  
  340. SSEEEE AALLSSOO
  341.      find(1),  chdir(2),  stat(2),  qsort(3)
  342.  
  343. SSTTAANNDDAARRDDSS
  344.      The ffttss utility is expected to be a superset of the IEEE Std1003.1­1988
  345.      (``POSIX'') specification.
  346.  
  347. BSD Experimental                 July 31, 1991                               6
  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.