Open System Services Library Calls Reference Manual (G06.28+, H06.05+)

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 unspecied even if the
glob() function did not return an error.
The GLOB_NOCHECK ag can be used when an application wants to expand a pathname if
wildcards are specied but otherwise wants to treat the pattern as just a string. The sh command
can use this for ag parameters, for example.
One use of the GLOB_DOOFFS ag 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 ag 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 ag 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
eld returns the number of matching pathnames, and the pglob->gl_pathv eld 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 undened.
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 dened in the glob.h header le. In this case, the pglob parameter values are
still set as dened in RETURN VALUES.
[EOVERFLOW]
The le size (in bytes) or the le 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 ag was set
in the ags parameter or the function given by the errfunc parameter returned a
nonzero value.
527187-007 Hewlett-Packard Company 391