|HP-UX Reference > G
HP-UX 11i Version 3: February 2007
glob(), globfree() — file name generation function
#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);
glob() 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, glob() requires:
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 associated 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>:
If, during the search, a directory is encountered that cannot be opened or read and errfunc is not NULL, glob() calls (*errfunc)() with two arguments:
If errfunc is called and returns nonzero, or if the GLOB_ERR flag is set in flags, glob() stops the scan and returns GLOB_ABORTED after setting gl_pathc and gl_pathv in pglob to reflect the paths already scanned. If GLOB_ERR 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:
The LC_COLLATE category determines the collating sequence used in compiling and executing regular expressions, and also the order of the returned paths if GLOB_NOSORT is not selected.
The LC_CTYPE 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.
If glob() terminates due to an error, it returns one of the following constants (defined in <glob.h>); otherwise, it returns zero.
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 undefined.
If the pattern argument passed to glob() is badly constructed, glob() returns zero and sets gl_pathc to zero unless GLOB_NOCHECK was set, in which case pattern is returned and gl_pathc is set to 1.