Open System Services Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)

OSS Library Calls (g - h) glob(3)
EXAMPLES
Note that the pglob parameter has meaning even if the glob( ) function fails. This allows the
glob( ) function to report partial results in the event of an error. However, if the number of
matched pathnames is 0 (zero), the pointer in the pglob parameter is unspecified even if the
glob( ) function did not return an error.
The GLOB_NOCHECK flag can be used when an application wants to expand a pathname if
wildcards are specified but otherwise wants to treat the pattern as just a string. The sh command
can use this for flag parameters, for example.
One use of the GLOB_DOOFFS flag is for applications that build an argument list for use with
the functions execv( ), execve( ), execvp( ), tdm_execve( ), tdm_execvep( ), tdm_spawn( ),or
tdm_spawnp( ). For example, if an application needs to do the equivalent of ls -l *.c but for
some reason this is not acceptable, the application could obtain approximately the same result
using the following sequence:
globbuf.gl_offs = 2;
glob ("*.c", GLOB_DOOFFS, NULL, &globbuf);
globbuf.gl_pathv[0] = "ls";
globbuf.gl_pathv[1] = "-l";
execvp ("ls", &globbuf.gl_pathv[0]);
Using the same example, ls -l *.c *.h could be approximated using the GLOB_APPEND flag as
follows:
globbuf.gl_offs = 2;
glob ("*.c", GLOB_DOOFFS, NULL, &globbuf);
glob ("*.h", GLOB_DOOFFS|GLOB_APPEND, NULL, &globbuf);
The new pathnames generated by a subsequent call with the GLOB_APPEND flag set are not
sorted together with the previous pathnames. This duplicates the way that the shell handles path-
name expansion when multiple expansions are done on a command line.
RETURN VALUES
On successful completion, the glob( ) function returns the value 0 (zero). The pglob->gl_pathc
field returns the number of matching pathnames, and the pglob->gl_pathv field contains a pointer
to a null-terminated list of matching and sorted pathnames. If the number of matching pathnames
in pglob->gl_pathc is 0 (zero), the pointer in pglob->gl_pathv is undefined.
If the glob( ) function terminates because of an error, it returns one of the nonzero constants
described in ERRORS.
ERRORS
If the glob( ) function terminates because of an error, it returns one of the following nonzero con-
stants. These are defined in the glob.h header file. In this case, the pglob parameter values are
still set as defined in RETURN VALUES.
[EOVERFLOW]
The file size (in bytes) or the file inode number (serial number) cannot be
represented correctly in a structure of type glob_t.
GLOB_ABORTED
Indicates that the scan was stopped because either the GLOB_ERR flag was set
in the flags parameter or the function given by the errfunc parameter returned a
nonzero value.
527187-017 Hewlett-Packard Company 3163