glob.3c (2010 09)

g
glob(3C) glob(3C)
NAME
glob(), globfree() - file name generation function
SYNOPSIS
#include <glob.h>
int glob(
const char *__restrict pattern,
int flags,
int (*errfunc)(const char *, int),
glob_t *__restrict pglob
);
void globfree(glob_t *pglob);
DESCRIPTION
glob() is a path name generator. pattern is a pointer to a path name pattern to be expanded. If pat-
tern contains any of the special characters
*
, ?,or[, pattern is matched against all accessible path
names. In order to have access to a path name,
glob() requires:
Search permission on every component of a path except the last.
Read permission on each directory of any file name component of pattern that contains any of the
above special characters.
glob() stores the number of matched path names in pglob > gl_pathc and a pointer to a sorted list of
path names in pglob >gl_pathv . The first pointer after the last path name is a NULL pointer.
It is the caller’s responsibility to allocate space for the structure pointed to by pglob .
glob() allocates
other space as needed, including the memory pointed to by gl_pathv .
globfree() frees any space asso-
ciated with pglob from a previous call to glob().
The flags argument is used to control the behavior of
glob(). The value of flags is the bit-wise inclusive
OR of the following constants defined in
<glob.h>:
GLOB_NOESCAPE Disable backslash escaping.
GLOB_ERR Causes glob() to return when it first encounters a directory that it cannot
open or read. Ordinarily, glob() continues to find matches.
GLOB_MARK Each path name that matches pattern and is a directory, has a / appended.
GLOB_NOSORT Ordinarily, glob() sorts the matching path names according to the currently
active collation sequence as defined by the LC_COLLATE category. When this
flag is used, the order of path names returned is unspecified.
GLOB_NOCHECK If pattern does not match any path name, glob() returns a list consisting of
only pattern , and the number of matched path names is 1.
GLOB_DOOFFS Make use of pglob > gl_offs. If this flag is set, pglob > gl_offs is used to
specify how many NULL pointers to add to the beginning of pglob > gl_pathv .
In other words, pglob > gl_pathv points to pglob > gl_offs NULL pointers, fol-
lowed by pglob > gl_pathc path name pointers, followed by a NULL pointer.
GLOB_APPEND Append path names generated to the ones from a previous call to glob().
The
GLOB_APPEND flag can be used to append a new set of path names to those found in a previous
call to glob(). The following rules apply when two or more calls to glob() are made with the
same value of pglob and without intervening calls to globfree():
The first call must not set
GLOB_APPEND. All subsequent calls must set it.
All of the calls must set
GLOB_DOOFFS, or all must not set it.
After the second call, pglob > gl_pathv points to a list containing the following:
Zero or more NULL pointers, as specified by
GOB_DOOFFS and pglob > gl_offs.
Pointers to the path names that were in the pglob > gl_pathv list before the call,
in the same order as before.
Pointers to the new path names generated by the second call, in the specified
order.
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (4 pages)