Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

glob(3head) [opensolaris man page]

glob.h(3HEAD)							      Headers							     glob.h(3HEAD)

NAME
glob.h, glob - pathname pattern-matching types SYNOPSIS
#include <glob.h> DESCRIPTION
The <glob.h> header defines the structures and symbolic constants used by the glob(3C). The structure type glob_t contains the following members: size_t gl_pathc /* count of paths matched by pattern */ char **gl_pathv /* pointer to a list of matched pathnames */ size_t gl_offs /* lots to reserve at the beginning of gl_pathv */ The following constants are provided as values for the flags argument: GLOB_APPEND Append generated pathnames to those previously obtained. GLOB_DOOFFS Specify how many null pointers to add to the beginning of gl_pathv. GLOB_ERR Cause glob() to return on error. GLOB_MARK Each pathname that is a directory that matches pattern has a slash appended. GLOB_NOCHECK If pattern does not match any pathname, then return a list consisting of only pattern. GLOB_NOESCAPE Disable backslash escaping. GLOB_NOSORT Do not sort the pathnames returned. The following constants are defined as error return values: GLOB_ABORTED The scan was stopped because GLOB_ERR was set or (*errfunc)() returned non-zero. GLOB_NOMATCH The pattern does not match any existing pathname, and GLOB_NOCHECK was not set in flags. GLOB_NOSPACE An attempt to allocate memory failed. GLOB_NOSYS Reserved. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
glob(3C), attributes(5), standards(5) SunOS 5.11 10 Sep 2004 glob.h(3HEAD)

Check Out this Related Man Page

GLOB(3) 						     Library Functions Manual							   GLOB(3)

NAME
glob, globfree - generate pathnames matching a pattern SYNOPSIS
#include <glob.h> glob(const char *pattern, int flags, const int (*errfunc)(char *, int), glob_t *pglob); void globfree(glob_t *pglob); DESCRIPTION
Glob is a pathname generator that implements the rules for file name pattern matching used by the shell. The include file glob.h defines the structure type glob_t, which contains at least the following fields: typedef struct { int gl_pathc; /* count of total paths so far */ int gl_matchc; /* count of paths matching pattern */ int gl_offs; /* reserved at beginning of gl_pathv */ int gl_flags; /* returned flags */ char **gl_pathv; /* list of paths matching pattern */ } glob_t; The argument pattern is a pointer to a pathname pattern to be expanded. Glob matches all accessible pathnames against the pattern and cre- ates a list of the pathnames that match. In order to have access to a pathname, glob requires search permission on every component of a path except the last and read permission on each directory of any filename component of pattern that contains any of the special characters ``*'', ``?'' or ``[''. Glob stores the number of matched pathnames into the gl_pathc field, and a pointer to a list of pointers to pathnames into the gl_pathv field. The first pointer after the last pathname is NULL. If the pattern does not match any pathnames, the returned number of matched paths is set to zero. It is the caller's responsibility to create the structure pointed to by pglob. The glob function allocates other space as needed, includ- ing the memory pointed to by gl_pathv. The argument flags is used to modify the behavior of glob. The value of flags is the bitwise inclusive OR of any of the following values defined in glob.h: GLOB_APPEND Append pathnames generated to the ones from a previous call (or calls) to glob. The value of gl_pathc will be the total matches found by this call and the previous call(s). The pathnames are appended to, not merged with the pathnames returned by the previous call(s). Between calls, the caller must not change the setting of the GLOB_DOOFFS flag, nor change the value of gl_offs when GLOB_DOOFFS is set, nor (obviously) call globfree for pglob. GLOB_DOOFFS Make use of the gl_offs field. If this flag is set, gl_offs is used to specify how many NULL pointers to prepend to the beginning of the gl_pathv field. In other words, gl_pathv will point to gl_offs NULL pointers, followed by gl_pathc pathname pointers, fol- lowed by a NULL pointer. GLOB_ERR Causes glob to return when it encounters a directory that it cannot open or read. Ordinarily, glob continues to find matches. GLOB_MARK Each pathname that is a directory that matches pattern has a slash appended. GLOB_NOSORT By default, the pathnames are sorted in ascending ASCII order; this flag prevents that sorting (speeding up glob). GLOB_NOCHECK If pattern does not match any pathname, then glob returns a list consisting of only pattern, with the number of total pathnames is set to 1, and the number of matched pathnames set to 0. If GLOB_QUOTE is set, its effect is present in the pattern returned. GLOB_QUOTE Use the backslash (``'') character for quoting: every occurrence of a backslash followed by a character in the pattern is replaced by that character, avoiding any special interpretation of the character. If, during the search, a directory is encountered that cannot be opened or read and errfunc is non-NULL, glob calls (*errfunc)(path, errno). This may be unintuitive: a pattern like ``*/Makefile'' will try to stat(2) ``foo/Makefile'' even if ``foo'' is not a directory, resulting in a call to errfunc. The error routine can suppress this action by testing for ENOENT and ENOTDIR; however, the GLOB_ERR flag will still cause an immediate return when this happens. If errfunc returns non-zero, glob stops the scan and returns GLOB_ABEND after setting gl_pathc and gl_pathv to reflect any paths already matched. This also happens if an error is encountered and GLOB_ERR is set in flags, regardless of the return value of errfunc, if called. If GLOB_ERR is not set and either errfunc is NULL or errfunc returns zero, the error is ignored. The globfree function frees any space associated with pglob from a previous call(s) to glob. RETURNS
On successful completion, glob returns zero. In addition the fields of pglob contain the values described below: gl_pathc contains the total number of matched pathnames so far. This includes other matches from previous invocations of glob if GLOB_APPEND was specified. gl_matchc contains the number of matched pathnames in the current invocation of glob. gl_flags contains a copy of the flags parameter with the bit GLOB_MAGCHAR set if pattern contained any of the special characters ``*'', ``?'' or ``['', cleared if not. gl_pathv contains a pointer to a NULL-terminated list of matched pathnames. However, if gl_pathc is zero, the contents of gl_pathv are unde- fined. If glob terminates due to an error, it sets errno and returns one of the following non-zero constants, which are defined in the include file <glob.h>: GLOB_NOSPACE An attempt to allocate memory failed. GLOB_ABEND The scan was stopped because an error was encountered and either GLOB_ERR was set or (*errfunc)() returned non-zero. The arguments pglob->gl_pathc and pglob->gl_pathv are still set as specified above. STANDARDS
The glob function is expected to be POSIX 1003.2 compatible with the exception that the flag GLOB_QUOTE and the fields gl_matchc and gl_flags should not be used by applications striving for strict POSIX conformance. EXAMPLE
A rough equivalent of ``ls -l *.c *.h'' can be obtained with the following code: glob_t g; g.gl_offs = 2; glob("*.c", GLOB_DOOFFS, NULL, &g); glob("*.h", GLOB_DOOFFS | GLOB_APPEND, NULL, &g); g.gl_pathv[0] = "ls"; g.gl_pathv[1] = "-l"; execvp("ls", g.gl_pathv); SEE ALSO
sh(1), fnmatch(3), wordexp(3), regexp(3) BUGS
Patterns longer than MAXPATHLEN may cause unchecked errors. Glob may fail and set errno for any of the errors specified for the library routines stat (2), closedir (3), opendir (3), readdir (3), mal- loc (3), and free (3). 4.4 Berkeley Distribution March 19, 1991 GLOB(3)
Man Page