glob

GLOB(3)                    Linux Programmer's Manual                   GLOB(3)



åå
       glob, globfree - ãã¿ã¼ã³ã«ããããããã¹åãè¦ä»ãããglob() ã«ãã£
       ã¦ç¢ºä¿ãããã¡ã¢ãªé åã解æ¾ããã

æ¸å¼
       #include <glob.h>

       int glob(const char *pattern, int flags,
                int (*errfunc) (const char *epath, int eerrno),
                glob_t *pglob);
       void globfree(glob_t *pglob);

説æ
       glob()  é¢æ°ã¯ã·ã§ã«ãç¨ãã¦ããã«ã¼ã« (glob(7)  åç§) ã«åºã¥ãã¦ãã¿ã¼ã³
       pattern ã«ããããããã¹ã¦ã®ãã¹åãæ¤ç´¢ããã ãã«ã (~)
       ã®å±éããã©ã¡ã¼ã¿ç½®æã¯è¡ãããªããããããè¡ãããå ´å㯠wordexp(3) ã使ãã¨ããã

       globfree()  é¢æ°ã¯åã«å¼ã°ãã glob()  ã«ããåçã«ç¢ºä¿ãããè¨æ¶é åã解æ¾ããã

       glob()  ã®çµæ㯠pglob ããã¤ã³ãããæ§é ä½ã«è¿ãããã pglob 㯠glob_t
       åã®æ§é ä½ã§ããã glob_t å㯠<glob.h>
       åã§å®£è¨ããã¦ããã以ä¸ã®è¦ç´ ãå«ãã§ããããããã®è¦ç´ 㯠POSIX.2 ã§å®ç¾© ããã¦ãã
       (ããã«å¤ãã®è¦ç´ ãæ¡å¼µã¨ãã¦å¥ã£ã¦ãããããããªã)ã

           typedef struct {
               size_t   gl_pathc;    /* ä»ã¾ã§ã«ããããããã¹ã®æ° */
               char   **gl_pathv;    /* ããããããã¹åã®ãªã¹ã */
               size_t   gl_offs;     /* gl_pathv åã«ç¢ºä¿ããã¹ãããæ° */
           } glob_t;

       çµæã¯åçã«ç¢ºä¿ãããè¨æ¶é åã«å¥ããããã

       ãã©ã¡ã¼ã¿ flags ã«ã¯ä»¥ä¸ã®ç¤ºãå®æ°ã®ãã¡ãæå®ããããã®ãããããã¨ã® OR ã§ä¸ãã
       (ä¸ã¤ã æå®ããªãã¦ããã)ãããã«ãã£ã¦ glob()  ã®åä½ãå¤æ´ã§ããã

       GLOB_ERR
              (ä¾ãã°ããã£ã¬ã¯ããªã«èªã¿åã許å¯å±æ§ãç¡ãå ´åãªã©ã§)  èª‐
              ã¿åãã¨ã©ã¼ãçºçããéã«é¢æ°ããæ»ãã ããã©ã«ãã§ã¯ãã¨ã©ã¼ã«é¢ããã èª‐
              ã¿åãå¯è½ãªãã£ã¬ã¯ããªãå¨ã¦ã«ã¤ãã¦èªã¿åããå®è¡ãããã¨ããã

       GLOB_MARK
              ãã£ã¬ã¯ããªã«å¯¾å¿ããåãã®ãã¹ã«ã¹ã©ãã·ã¥ãä»å ããã

       GLOB_NOSORT
              è¿ããããã¹åã®ã½ã¼ããè¡ããªãã
              ã½ã¼ããè¡ããªãçç±ã¯ãå¦çæéãç¯ç´ããããã ãã§ããã
              ããã©ã«ãã§ã¯ãè¿ããããã¹åã¯ã½ã¼ããããã

       GLOB_DOOFFS
              pglob->pathv ã®æååãªã¹ãã®åé ã« pglob->gl_offs ã¹ã‐
              ããåã®é åãäºç´ããã äºç´ãããã¹ãããã«ã¯ NULL ãã¤ã³ã¿ãå¥ãã

       GLOB_NOCHECK
              ããããããã¿ã¼ã³ããªããã°ãåã®ãã¿ã¼ã³ãè¿ãã ããã©ã«ãã§ã¯ã glob()
              ã¯ããããããã¿ã¼ã³ããªããã° GLOB_NOMATCH ãè¿ãã

       GLOB_APPEND
              ãã®å¼ã³åºãã§ã®çµæãç´åã® glob()
              ã®å¼ã³åºãã§è¿ãããçµæã®ãã¯ãã«ã«è¿½å ãããæåã® glob()
              ã®å¼ã³åºãã®éã«ã¯ãã®ãã©ã°ãè¨å®ãã¦ã¯ãããªãã

       GLOB_NOESCAPE
              ããã¯ã¹ã©ãã·ã¥ ('\') ãã¨ã¹ã±ã¼ãç¨æåã¨ãã¦ä½¿ç¨ã§ããªãã
              é常ã¯ãããã¯ã¹ã©ãã·ã¥ã使ã£ã¦ã次ã«ç¶ãæåãã¯ã©ã¼ããããã¨ã§ã
              ç¹å¥ãªæå³ãæã¤ã¡ã¿ãã£ã©ã¯ã¿ãç¡å¹ãããã¨ãã§ããã

       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}" ã¨ãããã¿ã¼ã³ã
              æå®ããå ´åã«å¾ãããçµæã¯ã 4ã¤ã®æåå "foo/", "foo/cat", "foo/dog",
              "bar" ã®ããããã«ã¤ã㦠glob()  ãå¼ã³åºããå ´åã¨åãã«ãªãã

       GLOB_NOMAGIC
              ãã¿ã¼ã³ã«ã¡ã¿ãã£ã©ã¯ã¿ãå«ã¾ãã¦ããªãå ´åã
              ãããçµæã¨ãã¦æå®ããããã¿ã¼ã³ã ããè¿ãã ãã¿ã¼ã³ã§æå®ãããååã®ãã¡ã¤ã«ãå‐
              å¨ããªãå ´åã§ãã£ã¦ãã ãã®ãã¿ã¼ã³ãè¿ãããã

       GLOB_TILDE
              ãã«ãã®å±éãè¡ãã ãã«ã ('~') ããã¿ã¼ã³åã®å¯ä¸ã®æå‐
              ã®å ´åããåé ã®ãã«ãã®ç´å¾ã®æåã ã¹ã©ãã·ã¥ ('/')
              ã®å ´åããã«ããå¼ã³åºãèã®ãã¼ã ãã£ã¬ã¯ããªã§ç½®æããã
              åé ã®ãã«ãã«ã¦ã¼ã¶åãç¶ãå ´å (ä¾ãã° "~andrea/bin")ã
              ãã«ãã¨ã¦ã¼ã¶åããã®ã¦ã¼ã¶ã®ãã¼ã ãã£ã¬ã¯ããªã§ç½®æããã
              ã¦ã¼ã¶åãç¡å¹ãªå ´åããã¼ã ãã£ã¬ã¯ããªã決å®ã§ããªãå ´åã¯ã
              ç½®æã¯å®è¡ãããªãã

       GLOB_TILDE_CHECK
              ãã®ãã©ã°ãæå®ãã㨠GLOB_TILDE ã¨åæ§ã®æ¯èããããã GLOB_TILDE
              ã¨ã®éãã¯ãã¦ã¼ã¶åãç¡å¹ã ã£ãå ´åã
              ãã¼ã ãã£ã¬ã¯ããªã決å®ã§ããªãã£ãå ´åã«ã
              ãã¿ã¼ã³èªèº«ã使ç¨ããã®ã§ã¯ãªãã glob()  ãã¨ã©ã¼ã示ã GLOB_NOMATCH
              ãè¿ããã¨ã§ããã

       GLOB_ONLYDIR
              ãã®ãã©ã°ã¯ã glob()  ã«å¯¾ããããã³ããã§ããã
              å¼ã³åºãå´ããã¿ã¼ã³ã«ããããããã£ã¬ã¯ããªã«ããèå³ããªããã¨ãç¥ãããã
              å®è£ã«ããã¦ãã¡ã¤ã«ã®ç¨®å¥æå ±ãç°¡åã«æ±ºå®ã§ããå ´åã¯ããã£ã¬ã¯ããªã§ãªã
              ãã¡ã¤ã«ã¯å¼ã³åºãå´ã«è¿ãããªããããããªãããå¼ã³åºãå´ã§ã¯ãè¿ããã
              ãã¡ã¤ã«ãªã¹ãããã£ã¬ã¯ããªãã©ããã確èªããªããã°ãªããªãã (ãã®ãã©ã°ãå‐
              å¨ããã®ã¯ãå¼ã³åºãå´ããã£ã¬ã¯ããªã«ããèå³ããªãéã«
              æ§è½ãæé©åããç®çã®ããã ãã§ããã)

       errfunc ã NULL ã§ãªããã°ã ã¨ã©ã¼ãèµ·ãã£ãå ´åã«ã¯é¢æ° errfunc
       ãå¼ã³åºããããé¢æ°ã®å¼æ°ã«ã¯ã失æãããã¹å epath 㨠errno (opendir(3),
       readdir(3), stat(2).  ã®ããããã«ãã£ã¦ã»ãããããå¤) ãä¸ããããã errfunc ã 0
       以å¤ã®å¤ãè¿ããããã㯠GLOB_ERR ãã»ãããããå ´å glob()  㯠errfunc
       ã®å¼ã³åºãå¾ã«çµäºããã

       å¼ã³åºããæåãã¦æ»ã£ãå ´å pglob->gl_pathc ã«ã¯ããããããã¹åãå«ã¾ãã
       pglob->gl_pathv ã¯ããããããã¹åã¸ã®ãã¤ã³ã¿ã®ãªã¹ãã¸ã®ãã¤ã³ã¿ã¨ãªãã
       ãã¤ã³ã¿ã®ãªã¹ã㯠NULL ãã¤ã³ã¿ã§çµç«¯ãããã

       glob()  ãä½åº¦ãç¶ãã¦å¼ã³åºããã¨ãã§ããããã®é2åç®ä»¥éã®å¼ã³åºãã§ã¯
       GLOB_APPEND ãã©ã°ã flags ã«è¨å®ããã¦ããªããã°ãªããªãã

       GNU ã®æ¡å¼µã¨ãã¦ã pglob->gl_flags
       ã«ã¯æå®ãããã©ã°ãã»ããããããããä¸ã¤ã§ãã¡ã¿ãã£ã©ã¯ã¿ãè¦ä»ããã° ãã®ãã©ã°ã¨
       GLOB_MAGCHAR ã¨ã® OR ãåã£ãçµæãã»ãããããã

è¿ãå¤
       å¼ã³åºããæåãã¦å®äºãã㨠glob()  㯠0 ãè¿ãã ãã以å¤ã®è¿ãå¤ã¯ä»¥ä¸ã®éã:

       GLOB_NOSPACE
              ã¡ã¢ãªã使ãæããã

       GLOB_ABORTED
              èªã¿åãã¨ã©ã¼

       GLOB_NOMATCH
              ä¸ã¤ããããããªãã£ã

æºæ
       POSIX.2, POSIX.1-2001.

注æ
       glibc 2.1 ã§ã¯ã gl_pathc 㨠gl_offs 㯠POSIX.2 ã§æå®ããã¦ããããã« size_t
       ã¨ãã¦å®£è¨ããã¦ããã libc4, libc5, glibc 2.0 ã§ã¯ã int ã¨ãã¦å®£è¨ããã¦ããã

ãã°
       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)

ãã®ææ¸ã«ã¤ãã¦
       ãã® man ãã¼ã¸ã¯ Linux man-pages ããã¸ã§ã¯ãã®ãªãªã¼ã¹ 3.51 ã®ä¸é¨
       ã§ãããããã¸ã§ã¯ãã®èª¬æã¨ãã°å ±åã«é¢ããæå ±ã¯
       http://www.kernel.org/doc/man-pages/ ã«æ¸ããã¦ããã



GNU                               2007-10-10                           GLOB(3)