home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / man / cat3 / glob.0 < prev    next >
Text File  |  1993-12-07  |  10KB  |  199 lines

  1.  
  2. GLOB(3)                    UNIX Programmer's Manual                    GLOB(3)
  3.  
  4. NNAAMMEE
  5.      gglloobb, gglloobbffrreeee - generate pathnames matching a pattern
  6.  
  7. SSYYNNOOPPSSIISS
  8.      ##iinncclluuddee <<gglloobb..hh>>
  9.  
  10.      _i_n_t
  11.      gglloobb(_c_o_n_s_t _c_h_a_r _*_p_a_t_t_e_r_n, _i_n_t _f_l_a_g_s, _c_o_n_s_t _i_n_t _(_*_e_r_r_f_u_n_c_)_(_c_h_a_r _*_, _i_n_t_),
  12.              _g_l_o_b___t _*_p_g_l_o_b)
  13.  
  14.      _v_o_i_d
  15.      gglloobbffrreeee(_g_l_o_b___t _*_p_g_l_o_b)
  16.  
  17. DDEESSCCRRIIPPTTIIOONN
  18.      The gglloobb() function is a pathname generator that implements the rules for
  19.      file name pattern matching used by the shell.
  20.  
  21.      The include file _g_l_o_b_._h defines the structure type _g_l_o_b___t, which contains
  22.      at least the following fields:
  23.  
  24.      typedef struct {
  25.              int gl_pathc;           /* count of total paths so far */
  26.              int gl_matchc;          /* count of paths matching pattern */
  27.              int gl_offs;            /* reserved at beginning of gl_pathv */
  28.              int gl_flags;           /* returned flags */
  29.              char **gl_pathv;        /* list of paths matching pattern */
  30.      } glob_t;
  31.  
  32.      The argument _p_a_t_t_e_r_n is a pointer to a pathname pattern to be expanded.
  33.      The gglloobb() argument matches all accessible pathnames against the pattern
  34.      and creates a list of the pathnames that match.  In order to have access
  35.      to a pathname, gglloobb() requires search permission on every component of a
  36.      path except the last and read permission on each directory of any file­
  37.      name component of _p_a_t_t_e_r_n that contains any of the special characters
  38.      `*', `?' or `['.
  39.  
  40.      The gglloobb() argument stores the number of matched pathnames into the
  41.      _g_l___p_a_t_h_c field, and a pointer to a list of pointers to pathnames into the
  42.      _g_l___p_a_t_h_v field.  The first pointer after the last pathname is NULL. If
  43.      the pattern does not match any pathnames, the returned number of matched
  44.      paths is set to zero.
  45.  
  46.      It is the caller's responsibility to create the structure pointed to by
  47.      _p_g_l_o_b. The gglloobb() function allocates other space as needed, including the
  48.      memory pointed to by _g_l___p_a_t_h_v.
  49.  
  50.      The argument _f_l_a_g_s is used to modify the behavior of gglloobb().  The value
  51.      of _f_l_a_g_s is the bitwise inclusive OR of any of the following values de­
  52.      fined in _g_l_o_b_._h:
  53.  
  54.      GLOB_APPEND   Append pathnames generated to the ones from a previous call
  55.                    (or calls) to gglloobb().  The value of _g_l___p_a_t_h_c will be the
  56.                    total matches found by this call and the previous call(s).
  57.                    The pathnames are appended to, not merged with the path­
  58.                    names returned by the previous call(s).  Between calls, the
  59.                    caller must not change the setting of the GLOB_DOOFFS flag,
  60.                    nor change the value of _g_l___o_f_f_s when GLOB_DOOFFS is set,
  61.                    nor (obviously) call gglloobbffrreeee() for _p_g_l_o_b.
  62.  
  63.      GLOB_DOOFFS   Make use of the _g_l___o_f_f_s field.  If this flag is set,
  64.                    _g_l___o_f_f_s is used to specify how many NULL pointers to
  65.                    prepend to the beginning of the _g_l___p_a_t_h_v field.  In other
  66.                    words, _g_l___p_a_t_h_v will point to _g_l___o_f_f_s NULL pointers, fol­
  67.                    lowed by _g_l___p_a_t_h_c pathname pointers, followed by a NULL
  68.                    pointer.
  69.  
  70.      GLOB_ERR      Causes gglloobb() to return when it encounters a directory that
  71.                    it cannot open or read.  Ordinarily, gglloobb() continues to
  72.                    find matches.
  73.  
  74.      GLOB_MARK     Each pathname that is a directory that matches _p_a_t_t_e_r_n has
  75.                    a slash appended.
  76.  
  77.      GLOB_NOCHECK  If _p_a_t_t_e_r_n does not match any pathname, then gglloobb() returns
  78.                    a list consisting of only _p_a_t_t_e_r_n, with the number of total
  79.                    pathnames is set to 1, and the number of matched pathnames
  80.                    set to 0.  If GLOB_QUOTE is set, its effect is present in
  81.                    the pattern returned.
  82.  
  83.      GLOB_NOMAGIC  Is the same as GLOB_NOCHECK but it only appends the _p_a_t_t_e_r_n
  84.                    if it does not contain any of the special characters ``*'',
  85.                    ``?'' or ``[''.  GLOB_NOMAGIC is provided to simplify im­
  86.                    plementing the historic csh(1) globbing behavior and should
  87.                    probably not be used anywhere else.
  88.  
  89.      GLOB_NOSORT   By default, the pathnames are sorted in ascending ASCII or­
  90.                    der; this flag prevents that sorting (speeding up gglloobb()).
  91.  
  92.      GLOB_QUOTE    Use the backslash (`\') character for quoting: every occur­
  93.                    rence of a backslash followed by a character in the pattern
  94.                    is replaced by that character, avoiding any special inter­
  95.                    pretation of the character.
  96.  
  97.      If, during the search, a directory is encountered that cannot be opened
  98.      or read and _e_r_r_f_u_n_c is non­NULL, gglloobb() calls _(_*_e_r_r_f_u_n_c_)_(_p_a_t_h_,_e_r_r_n_o_).
  99.      This may be unintuitive: a pattern like `*/Makefile' will try to stat(2)
  100.      `foo/Makefile' even if `foo' is not a directory, resulting in a call to
  101.      _e_r_r_f_u_n_c. The error routine can suppress this action by testing for ENOENT
  102.      and ENOTDIR; however, the GLOB_ERR flag will still cause an immediate re­
  103.      turn when this happens.
  104.  
  105.      If _e_r_r_f_u_n_c returns non­zero, gglloobb() stops the scan and returns GLOB_ABEND
  106.      after setting _g_l___p_a_t_h_c and _g_l___p_a_t_h_v to reflect any paths already matched.
  107.      This also happens if an error is encountered and GLOB_ERR is set in
  108.      _f_l_a_g_s, regardless of the return value of _e_r_r_f_u_n_c, if called.  If GLOB_ERR
  109.      is not set and either _e_r_r_f_u_n_c is NULL or _e_r_r_f_u_n_c returns zero, the error
  110.      is ignored.
  111.  
  112.      The gglloobbffrreeee() function frees any space associated with _p_g_l_o_b from a pre­
  113.      vious call(s) to gglloobb().
  114.  
  115. RREETTUURRNN VVAALLUUEESS
  116.      On successful completion, gglloobb() returns zero.  In addition the fields of
  117.      _p_g_l_o_b contain the values described below:
  118.  
  119.      _g_l___p_a_t_h_c      contains the total number of matched pathnames so far.
  120.                    This includes other matches from previous invocations of
  121.                    gglloobb() if GLOB_APPEND was specified.
  122.  
  123.      _g_l___m_a_t_c_h_c     contains the number of matched pathnames in the current in­
  124.                    vocation of gglloobb().
  125.  
  126.      _g_l___f_l_a_g_s      contains a copy of the _f_l_a_g_s parameter with the bit
  127.                    GLOB_MAGCHAR set if _p_a_t_t_e_r_n contained any of the special
  128.                    characters ``*'', ``?'' or ``['', cleared if not.
  129.  
  130.      _g_l___p_a_t_h_v      contains a pointer to a NULL­terminated list of matched
  131.                    pathnames.  However, if _g_l___p_a_t_h_c is zero, the contents of
  132.                    _g_l___p_a_t_h_v are undefined.
  133.  
  134.      If gglloobb() terminates due to an error, it sets errno and returns one of
  135.      the following non­zero constants, which are defined in the include file
  136.      <_g_l_o_b_._h>:
  137.  
  138.      GLOB_NOSPACE  An attempt to allocate memory failed.
  139.  
  140.      GLOB_ABEND    The scan was stopped because an error was encountered and
  141.                    either GLOB_ERR was set or _(_*_e_r_r_f_u_n_c_)_(_) returned non­zero.
  142.  
  143.      The arguments _p_g_l_o_b_-_>_g_l___p_a_t_h_c and _p_g_l_o_b_-_