glob(3C)glob(3C)NAMEglob(), globfree() - file name generation function
is a path name generator. pattern is a pointer to a path name pattern
to be expanded. If pattern contains any of the special characters or
pattern is matched against all accessible path names. In order to have
access to a path name, requires:
· Search permission on every component of a path except the
· Read permission on each directory of any file name component
of pattern that contains any of the above special characters.
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. allocates other space as needed, including the
memory pointed to by gl_pathv. frees any space associated with pglob
from a previous call to
The flags argument is used to control the behavior of The value of
flags is the bit-wise inclusive OR of the following constants defined
Disable backslash escaping.
Causes to return when it first encounters a direc‐
tory that it cannot open or read. Ordinar‐
ily, continues to find matches.
Each path name that matches
pattern and is a directory, has a appended.
Ordinarily, sorts the matching path names according to
the currently active collation sequence as
defined by the category. When this flag is
used, the order of path names returned is
If pattern does not match any path name,
returns a list consisting of only pattern,
and the number of matched path names is 1.
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, followed by pglob−>gl_pathc
path name pointers, followed by a NULL
Append path names generated to the ones from a previous call to
The flag can be used to append a new set of path names to those
found in a previous call to The following rules apply when two
or more calls to are made with the same value of pglob and with‐
out intervening calls to
· The first call must not set All subsequent calls must
· All of the calls must set 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
· 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.
· The count returned in pglob−>gl_pathc will be the
total number of path names from the two calls.
· The application can change any of the fields after a
call to If it does, it must reset them to the original
value before a subsequent call, using the same pglob
value, to or with the flag.
If, during the search, a directory is encountered that cannot be opened
or read and errfunc is not NULL, calls (*errfunc)() with two arguments:
· A pointer to the path that failed.
· The value of from the failure.
If errfunc is called and returns nonzero, or if the flag is set in
flags, stops the scan and returns after setting and in pglob to reflect
the paths already scanned. If is not set and either errfunc is NULL or
(*errfunc)() returns zero, the error is ignored.
Pattern Matching Notation
The form of the patterns is the Pattern Matching Notation as qualified
for Filename Expansion (see regexp(5)) with the following exceptions:
· Tilde expansion is not performed.
· Variable expansion is not performed.
The category determines the collating sequence used in compiling and
executing regular expressions, and also the order of the returned paths
if is not selected.
The category determines the interpretation of text as single byte
and/or multibyte characters, and determines which characters are
matched by character class expressions in regular expressions.
International Code Set Support
Single byte and multibyte character code sets are supported.
If terminates due to an error, it returns one of the following con‐
stants (defined in otherwise, it returns zero.
An attempt to allocate memory failed.
The scan was stopped because
was set or (*errfunc)() returned nonzero.
The pattern does not match any existing path
name, and was not set in flags.
In any case, the argument pglob−>gl_pathc returns the number of matched
path names and the argument pglob−>gl_pathv contains a pointer to a
null-terminated list of matched and sorted path names.
However, if pglob−>gl_pathc is zero, the content of pglob−>gl_pathv is
If the pattern argument passed to is badly constructed, returns zero
and sets to zero unless was set, in which case pattern is returned and
is set to 1.
must not be set in an initial call to
and were developed by OSF and HP.
SEE ALSOsh(1), fnmatch(3C), regexp(5), thread_safety(5).