glob(3) Library Functions Manual glob(3) glob, globfree - , glob() LIBRARY Standard C library (libc, -lc) #include int glob(const char *restrict pattern, int flags, int (*errfunc)(const char *epath, int eerrno), glob_t *restrict pglob); void globfree(glob_t *pglob); glob() pattern, , ( glob(7)). ; , wordexp(3). globfree() , glob(). glob() , pglob. glob_t ( ) , POSIX.2 ( , ): typedef struct { size_t gl_pathc; /* */ char **gl_pathv; /* . */ size_t gl_offs; /* gl_pathv . */ } glob_t; . flags , glob(): GLOB_ERR (, ). glob() , , . GLOB_MARK , . GLOB_NOSORT . . . GLOB_DOOFFS pglob->gl_offs pglob->pathv. null. GLOB_NOCHECK , . glob() GLOB_NOMATCH. GLOB_APPEND , glob(). glob(). GLOB_NOESCAPE Don't allow backslash ('\') to be used as an escape character. Normally, a backslash can be used to quote the following character, providing a mechanism to turn off the special meaning metacharacters. flags , GNU POSIX.2: GLOB_PERIOD . . GLOB_ALTDIRFUNC pglob->gl_closedir, pglob->gl_readdir, pglob->gl_opendir, pglob->gl_lstat pglob->gl_stat . GLOB_BRACE {a,b} csh(1). . , , "{foo/{,cat,dog},bar}" glob() : "foo/", "foo/cat", "foo/dog" "bar". GLOB_NOMAGIC , , . GLOB_TILDE Carry out tilde expansion. If a tilde ('~') is the only character in the pattern, or an initial tilde is followed immediately by a slash ('/'), then the home directory of the caller is substituted for the tilde. If an initial tilde is followed by a username (e.g., "~andrea/bin"), then the tilde and username are substituted by the home directory of that user. If the username is invalid, or the home directory cannot be determined, then no substitution is performed. GLOB_TILDE_CHECK GLOB_TILDE. , , , glob() GLOB_NOMATCH . GLOB_ONLYDIR glob() , , . , . , , -- ( -- , ). errfunc NULL, epath ( , ) eerrno ( errno opendir(3), readdir(3) stat(2)). errfunc GLOB_ERR , glob() errfunc. pglob->gl_pathc , pglob->gl_pathv . null. glob() . GLOB_APPEND flags . GNU, pglob->gl_flags -- , GLOB_MAGCHAR ( ). glob() . : GLOB_NOSPACE GLOB_ABORTED GLOB_NOMATCH attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |glob() | | MT-Unsafe race:utent env | | | | sig:ALRM timer locale | +----------------------------+----------------------------------------------------------+--------------------------+ |globfree() | | MT-Safe | +----------------------------+----------------------------------------------------------+--------------------------+ utent race:utent , setutent(3), getutent(3) endutent(3) , . glob(), race:utent . POSIX.1-2008. POSIX.1-2001, POSIX.2. gl_pathc gl_offs size_t glibc 2.1 ( , POSIX.2), int glibc 2.0. glob() - : malloc(3) opendir(3). errno. , ls -l *.c ../*.c : glob_t globbuf; globbuf.gl_offs = 2; glob("*.c", GLOB_DOOFFS, NULL, &globbuf); glob("../*.c", GLOB_DOOFFS | GLOB_APPEND, NULL, &globbuf); globbuf.gl_pathv[0] = "ls"; globbuf.gl_pathv[1] = "-l"; execvp("ls", &globbuf.gl_pathv[0]); . ls(1), sh(1), stat(2), exec(3), fnmatch(3), malloc(3), opendir(3), readdir(3), wordexp(3), glob(7) Azamat Hackimov , Dmitry Bolkhovskikh , Vladislav , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . glob(3)