Table of Contents

NAME

SYNOPSIS

DESCRIPTION

The function is a pathname generator that implements the rules for file name pattern matching used by the shell. The include file defines the structure type 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 is a pointer to a pathname pattern to be expanded. The argument matches all accessible pathnames against the pattern and creates a list of the pathnames that match. In order to have access to a pathname, requires search permission on every component of a path except the last and read permission on each directory of any filename component of that contains any of the special characters or The argument stores the number of matched pathnames into the field, and a pointer to a list of pointers to pathnames into the field. The first pointer after the last pathname is 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 The function allocates other space as needed, including the memory pointed to by The argument is used to modify the behavior of The value of is the bitwise inclusive of any of the following values defined in Append pathnames generated to the ones from a previous call (or calls) to The value of 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 flag, nor change the value of when is set, nor (obviously) call for Make use of the field. If this flag is set, is used to specify how many pointers to prepend to the beginning of the field. In other words, will point to pointers, followed by pathname pointers, followed by a pointer. Causes to return when it encounters a directory that it cannot open or read. Ordinarily, continues to find matches. Each pathname that is a directory that matches has a slash appended. If does not match any pathname, then returns a list consisting of only with the number of total pathnames is set to 1, and the number of matched pathnames set to 0. If is set, its effect is present in the pattern returned. By default, the pathnames are sorted in ascending order; this flag prevents that sorting (speeding up The following values may also be included in however, they are non-standard extensions to The following additional fields in the pglob structure have been initialized with alternate functions for glob to use to open, read, and close directories and to get stat information on names found in those directories.    void *(*gl_opendir)(const char * name);
   struct dirent *(*gl_readdir)(void *);
   void (*gl_closedir)(void *);
   int (*gl_lstat)(const char *name, struct stat *st);
   int (*gl_stat)(const char *name, struct stat *st);
This extension is provided to allow programs such as to provide globbing from directories stored on tape. Pre-process the pattern string to expand strings like is left unexpanded for historical reasons does the same thing to ease typing of patterns). Set by the function if the pattern included globbing characters. See the description of the usage of the structure member for more details. Is the same as but it only appends the if it does not contain any of the special characters ‘‘*’’, ‘‘?’’ or ‘‘[’’. is provided to simplify implementing the historic globbing behavior and should probably not be used anywhere else. 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. Expand patterns that start with to user name home directories. If, during the search, a directory is encountered that cannot be opened or read and is calls This may be unintuitive: a pattern like will try to even if is not a directory, resulting in a call to The error routine can suppress this action by testing for and however, the flag will still cause an immediate return when this happens. If returns non-zero, stops the scan and returns after setting and to reflect any paths already matched. This also happens if an error is encountered and is set in regardless of the return value of if called. If is not set and either is or returns zero, the error is ignored. The function frees any space associated with from a previous call(s) to

RETURN VALUES

On successful completion, returns zero. In addition the fields of contain the values described below: contains the total number of matched pathnames so far. This includes other matches from previous invocations of if was specified. contains the number of matched pathnames in the current invocation of contains a copy of the parameter with the bit set if contained any of the special characters ‘‘*’’, ‘‘?’’ or ‘‘[’’, cleared if not. contains a pointer to a list of matched pathnames. However, if is zero, the contents of are undefined. If terminates due to an error, it sets and returns one of the following non-zero constants, which are defined in the include file An attempt to allocate memory failed. The scan was stopped because an error was encountered and either was set or returned non-zero. The arguments and are still set as specified above.

EXAMPLE

A rough equivalent of 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

STANDARDS

The function is expected to be compatible with the exception that the flags and and the fields and should not be used by applications striving for strict conformance.

HISTORY

The and functions first appeared in

BUGS

Patterns longer than may cause unchecked errors. The function may fail and set for any of the errors specified for the library routines and


Table of Contents