| Skip Navigation Links | |
| Exit Print View | |
![]() | man pages section 3: Basic Library Functions Oracle Solaris 11 Information Library |
enable_extended_FILE_stdio(3C)
posix_spawnattr_getschedparam(3C)
posix_spawnattr_getschedpolicy(3C)
posix_spawnattr_getsigdefault(3C)
posix_spawnattr_getsigignore_np(3C)
posix_spawnattr_getsigmask(3C)
posix_spawnattr_setschedparam(3C)
posix_spawnattr_setschedpolicy(3C)
posix_spawnattr_setsigdefault(3C)
posix_spawnattr_setsigignore_np(3C)
posix_spawnattr_setsigmask(3C)
posix_spawn_file_actions_addclose(3C)
posix_spawn_file_actions_addclosefrom_np(3C)
posix_spawn_file_actions_adddup2(3C)
posix_spawn_file_actions_addopen(3C)
posix_spawn_file_actions_destroy(3C)
posix_spawn_file_actions_init(3C)
pthread_attr_getdetachstate(3C)
pthread_attr_getinheritsched(3C)
pthread_attr_getschedparam(3C)
pthread_attr_getschedpolicy(3C)
pthread_attr_setdetachstate(3C)
pthread_attr_setinheritsched(3C)
pthread_attr_setschedparam(3C)
pthread_attr_setschedpolicy(3C)
pthread_barrierattr_destroy(3C)
pthread_barrierattr_getpshared(3C)
pthread_barrierattr_setpshared(3C)
pthread_condattr_getpshared(3C)
pthread_condattr_setpshared(3C)
pthread_cond_reltimedwait_np(3C)
pthread_key_create_once_np(3C)
pthread_mutexattr_getprioceiling(3C)
pthread_mutexattr_getprotocol(3C)
pthread_mutexattr_getpshared(3C)
pthread_mutexattr_getrobust(3C)
pthread_mutexattr_setprioceiling(3C)
pthread_mutexattr_setprotocol(3C)
pthread_mutexattr_setpshared(3C)
pthread_mutexattr_setrobust(3C)
pthread_mutex_getprioceiling(3C)
pthread_mutex_reltimedlock_np(3C)
pthread_mutex_setprioceiling(3C)
pthread_rwlockattr_destroy(3C)
pthread_rwlockattr_getpshared(3C)
pthread_rwlockattr_setpshared(3C)
pthread_rwlock_reltimedrdlock_np(3C)
pthread_rwlock_reltimedwrlock_np(3C)
pthread_rwlock_timedrdlock(3C)
pthread_rwlock_timedwrlock(3C)
rctlblk_get_enforced_value(3C)
- generate path names matching a pattern
#include <glob.h>intglob(const char *restrictpattern,intflags,int(*errfunc)(const char *epath, inteerrno),glob_t *restrictpglob);
voidglobfree(glob_t *pglob);
Theglob() function is a path name generator.
Theglobfree() function frees any memory allocated byglob() associated withpglob.
The argumentpattern is a pointer to a path name pattern tobe expanded. Theglob() function matches all accessible path names against thispattern and develops a list of all path names that match. Inorder to have access to a path name,glob() requires search permission onevery component of a path except the last, and read permission oneach directory of any filename component ofpattern that contains any ofthe following special characters:
* ? [
The structure typeglob_t is defined in the header<glob.h> and includesat least the following members:
size_t gl_pathc; /* count of paths matched by */ /* pattern */char **gl_pathv; /* pointer to list of matched */ /* path names */size_t gl_offs; /* slots to reserve at beginning */ /* of gl_pathv */
Theglob() function stores the number of matched path names intopglob->gl_pathcand a pointer to a list of pointers to path names intopglob->gl_pathv. The path names are in sort order as defined by the currentsetting of theLC_COLLATE category. The first pointer after the lastpath name is aNULL pointer. If the pattern does not matchany path names, the returned number of matched paths is set to0, and the contents ofpglob->gl_pathv are implementation-dependent.
It is the caller's responsibility to create the structure pointed to bypglob. Theglob() function allocates other space as needed, including the memorypointed to bygl_pathv. Theglobfree() function frees any space associated withpglobfrom a previous call toglob().
Theflags argument is used to control the behavior ofglob(). Thevalue offlags is a bitwise inclusive OR of zero or moreof the following constants, which are defined in the header <glob.h>:
Append path names generated to the ones from a previous call toglob().
Make use ofpglob->gl_offs. If this flag is set,pglob->gl_offs is used to specify how manyNULL pointers to add to the beginning ofpglob->gl_pathv. In other words,pglob->gl_pathv will point topglob->gl_offsNULL pointers, followed bypglob->gl_pathc path name pointers, followed by aNULL pointer.
Causesglob() to return when it encounters a directory that it cannot open or read. Ordinarily,glob() continues to find matches.
Each path name that is a directory that matchespattern has a slash appended.
Ifpattern does not match any path name, thenglob() returns a list consisting of onlypattern, and the number of matched path names is 1.
Disable backslash escaping.
Ordinarily,glob() sorts the matching path names according to the current setting of theLC_COLLATE category. When this flag is used the order of path names returned is unspecified.
TheGLOB_APPEND flag can be used to append a new set ofpath names to those found in a previous call toglob(). Thefollowing rules apply when two or more calls toglob() are madewith the same value ofpglob and without intervening calls toglobfree():
The first such call must not setGLOB_APPEND. All subsequent calls must set it.
All the calls must setGLOB_DOOFFS, or all must not set it.
After the second call,pglob->gl_pathv points to a list containing the following:
Zero or moreNULL pointers, as specified byGLOB_DOOFFS andpglob->gl_offs.
Pointers to the path names that were in thepglob->gl_pathv list before the call, in the same order as before.
Pointers to the new path names generated by the second call, in the specified order.
The count returned inpglob->gl_pathc will be the total number of path names from the two calls.
The application can change any of the fields after a call toglob(). If it does, it must reset them to the original value before a subsequent call, using the samepglob value, toglobfree() orglob() with theGLOB_APPEND flag.
If, during the search, a directory is encountered that cannot be openedor read anderrfunc is not aNULL pointer,glob() calls(*errfunc)with two arguments:
Theepath argument is a pointer to the path that failed.
Theeerrno argument is the value oferrno from the failure, as set by theopendir(3C),readdir(3C) orstat(2) functions. (Other values may be used to report other errors not explicitly documented for those functions.)
The following constants are defined as error return values forglob():
The scan was stopped becauseGLOB_ERR was set or(*errfunc) returned non-zero.
The pattern does not match any existing path name, andGLOB_NOCHECK was not set in flags.
An attempt to allocate memory failed.
If(*errfunc) is called and returns non-zero, or if theGLOB_ERR flagis set inflags,glob() stops the scan and returnsGLOB_ABORTED after settinggl_pathc andgl_pathv inpglob to reflect the paths already scanned. IfGLOB_ERR is not set and eithererrfunc is aNULL pointer or(*errfunc) returns 0, the error is ignored.
The following values are returned byglob():
Successful completion. The argumentpglob->gl_pathc returns the number of matched path names and the argumentpglob->gl_pathv contains a pointer to a null-terminated list of matched and sorted path names. However, ifpglob->gl_pathc is 0, the content ofpglob->gl_pathv is undefined.
An error has occurred. Non-zero constants are defined in <glob.h>. The argumentspglob->gl_pathc andpglob->gl_pathv are still set as defined above.
Theglobfree() function returns no value.
This function is not provided for the purpose of enabling utilities toperform path name expansion on their arguments, as this operation is performedby the shell, and utilities are explicitly not expected to redo this.Instead, it is provided for applications that need to do path nameexpansion on strings obtained from other sources, such as a pattern typed bya user or read from a file.
If a utility needs to see if a path name matches agiven pattern, it can usefnmatch(3C).
Note thatgl_pathc andgl_pathv have meaning even ifglob() fails. Thisallowsglob() to report partial results in the event of an error.However, ifgl_pathc is 0,gl_pathv is unspecified even ifglob() did notreturn an error.
TheGLOB_NOCHECK option could be used when an application wants to expanda path name if wildcards are specified, but wants to treat thepattern as just a string otherwise.
The new path names generated by a subsequent call withGLOB_APPEND arenot sorted together with the previous path names. This mirrors the waythat the shell handles path name expansion when multiple expansions are doneon a command line.
Applications that need tilde and parameter expansion should use thewordexp(3C) function.
Example 1 Example ofglob_doofs function.
One use of theGLOB_DOOFFS flag is by applications that build anargument list for use with theexecv(),execve(), orexecvp() functions (seeexec(2)). Suppose, for example, that an application wants to do the equivalentof:
ls-l *.c
but for some reason:
system("ls -l *.c")is not acceptable. The application could obtain approximately the same result usingthe 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 approximately simulated usingGLOB_APPEND as follows:
globbuf.gl_offs = 2;glob ("*.c", GLOB_DOOFFS, NULL, &globbuf);glob ("*.h", GLOB_DOOFFS|GLOB_APPEND, NULL, &globbuf);. . .Seeattributes(5) for descriptions of the following attributes:
|
execv(2),stat(2),fnmatch(3C),opendir(3C),readdir(3C),wordexp(3C),attributes(5),standards(5)
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |