[BACK]Return to glob.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / gen

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/lib/libc/gen/glob.c between version 1.18.2.1 and 1.31.2.1

version 1.18.2.1, 2010/08/05 01:43:20 version 1.31.2.1, 2014/05/22 11:36:52
Line 59  __RCSID("$NetBSD$");
Line 59  __RCSID("$NetBSD$");
  *      expand ~user/foo to the /home/dir/of/user/foo   *      expand ~user/foo to the /home/dir/of/user/foo
  * GLOB_BRACE:   * GLOB_BRACE:
  *      expand {1,2}{a,b} to 1a 1b 2a 2b   *      expand {1,2}{a,b} to 1a 1b 2a 2b
    * GLOB_PERIOD:
    *      allow metacharacters to match leading dots in filenames.
    * GLOB_NO_DOTDIRS:
    *      . and .. are hidden from wildcards, even if GLOB_PERIOD is set.
  * gl_matchc:   * gl_matchc:
  *      Number of matches in the current invocation of glob.   *      Number of matches in the current invocation of glob.
  */   */
Line 74  __RCSID("$NetBSD$");
Line 78  __RCSID("$NetBSD$");
 #include <glob.h>  #include <glob.h>
 #include <pwd.h>  #include <pwd.h>
 #include <stdio.h>  #include <stdio.h>
   #include <stddef.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
Line 82  __RCSID("$NetBSD$");
Line 87  __RCSID("$NetBSD$");
 #define NO_GETPW_R  #define NO_GETPW_R
 #endif  #endif
   
 #define GLOB_LIMIT_MALLOC       65536  #define GLOB_LIMIT_STRING       65536   /* number of readdirs */
 #define GLOB_LIMIT_STAT         128  #define GLOB_LIMIT_STAT         128     /* number of stat system calls */
 #define GLOB_LIMIT_READDIR      16384  #define GLOB_LIMIT_READDIR      16384   /* total buffer size of path strings */
   #define GLOB_LIMIT_PATH         1024    /* number of path elements */
 #define GLOB_INDEX_MALLOC       0  #define GLOB_LIMIT_BRACE        128     /* Number of brace calls */
 #define GLOB_INDEX_STAT         1  
 #define GLOB_INDEX_READDIR      2  struct glob_limit {
           size_t l_string;
           size_t l_stat;
           size_t l_readdir;
           size_t l_brace;
   };
   
 /*  /*
  * XXX: For NetBSD 1.4.x compatibility. (kill me l8r)   * XXX: For NetBSD 1.4.x compatibility. (kill me l8r)
Line 122  __RCSID("$NetBSD$");
Line 132  __RCSID("$NetBSD$");
 #define M_MASK          0xffff  #define M_MASK          0xffff
 #define M_ASCII         0x00ff  #define M_ASCII         0x00ff
   
 typedef u_short Char;  typedef unsigned short Char;
   
 #else  #else
   
Line 153  static int  g_lstat(Char *, __gl_stat_t 
Line 163  static int  g_lstat(Char *, __gl_stat_t 
 static DIR      *g_opendir(Char *, glob_t *);  static DIR      *g_opendir(Char *, glob_t *);
 static Char     *g_strchr(const Char *, int);  static Char     *g_strchr(const Char *, int);
 static int       g_stat(Char *, __gl_stat_t *, glob_t *);  static int       g_stat(Char *, __gl_stat_t *, glob_t *);
 static int       glob0(const Char *, glob_t *, size_t *);  static int       glob0(const Char *, glob_t *, struct glob_limit *);
 static int       glob1(Char *, glob_t *, size_t *);  static int       glob1(Char *, glob_t *, struct glob_limit *);
 static int       glob2(Char *, Char *, Char *, Char *, glob_t *,  static int       glob2(Char *, Char *, Char *, const Char *, glob_t *,
     size_t *);      struct glob_limit *);
 static int       glob3(Char *, Char *, Char *, Char *, Char *, glob_t *,  static int       glob3(Char *, Char *, Char *, const Char *, const Char *,
     size_t *);      const Char *, glob_t *, struct glob_limit *);
 static int       globextend(const Char *, glob_t *, size_t *);  static int       globextend(const Char *, glob_t *, struct glob_limit *);
 static const Char *globtilde(const Char *, Char *, size_t, glob_t *);  static const Char *globtilde(const Char *, Char *, size_t, glob_t *);
 static int       globexp1(const Char *, glob_t *, size_t *);  static int       globexp1(const Char *, glob_t *, struct glob_limit *);
 static int       globexp2(const Char *, const Char *, glob_t *, int *,  static int       globexp2(const Char *, const Char *, glob_t *, int *,
     size_t *);      struct glob_limit *);
 static int       match(Char *, Char *, Char *);  static int       match(const Char *, const Char *, const Char *);
 #ifdef DEBUG  #ifdef DEBUG
 static void      qprintf(const char *, Char *);  static void      qprintf(const char *, Char *);
 #endif  #endif
   
 int  int
 glob(const char *pattern, int flags, int (*errfunc)(const char *, int),  glob(const char * __restrict pattern, int flags, int (*errfunc)(const char *,
     glob_t *pglob)      int), glob_t * __restrict pglob)
 {  {
         const u_char *patnext;          const unsigned char *patnext;
         int c;          int c;
         Char *bufnext, *bufend, patbuf[MAXPATHLEN+1];          Char *bufnext, *bufend, patbuf[MAXPATHLEN+1];
         /* 0 = malloc(), 1 = stat(), 2 = readdir() */          struct glob_limit limit = { 0, 0, 0, 0 };
         size_t limit[] = { 0, 0, 0 };  
   
         _DIAGASSERT(pattern != NULL);          _DIAGASSERT(pattern != NULL);
   
         patnext = (const u_char *) pattern;          patnext = (const unsigned char *) pattern;
         if (!(flags & GLOB_APPEND)) {          if (!(flags & GLOB_APPEND)) {
                 pglob->gl_pathc = 0;                  pglob->gl_pathc = 0;
                 pglob->gl_pathv = NULL;                  pglob->gl_pathv = NULL;
Line 213  glob(const char *pattern, int flags, int
Line 222  glob(const char *pattern, int flags, int
         *bufnext = EOS;          *bufnext = EOS;
   
         if (flags & GLOB_BRACE)          if (flags & GLOB_BRACE)
             return globexp1(patbuf, pglob, limit);              return globexp1(patbuf, pglob, &limit);
         else          else
             return glob0(patbuf, pglob, limit);              return glob0(patbuf, pglob, &limit);
 }  }
   
 /*  /*
Line 224  glob(const char *pattern, int flags, int
Line 233  glob(const char *pattern, int flags, int
  * characters   * characters
  */   */
 static int  static int
 globexp1(const Char *pattern, glob_t *pglob, size_t *limit)  globexp1(const Char *pattern, glob_t *pglob, struct glob_limit *limit)
 {  {
         const Char* ptr = pattern;          const Char* ptr = pattern;
         int rv;          int rv;
Line 232  globexp1(const Char *pattern, glob_t *pg
Line 241  globexp1(const Char *pattern, glob_t *pg
         _DIAGASSERT(pattern != NULL);          _DIAGASSERT(pattern != NULL);
         _DIAGASSERT(pglob != NULL);          _DIAGASSERT(pglob != NULL);
   
           if ((pglob->gl_flags & GLOB_LIMIT) &&
               limit->l_brace++ >= GLOB_LIMIT_BRACE) {
                   errno = 0;
                   return GLOB_NOSPACE;
           }
   
         /* Protect a single {}, for find(1), like csh */          /* Protect a single {}, for find(1), like csh */
         if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)          if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)
                 return glob0(pattern, pglob, limit);                  return glob0(pattern, pglob, limit);
Line 251  globexp1(const Char *pattern, glob_t *pg
Line 266  globexp1(const Char *pattern, glob_t *pg
  */   */
 static int  static int
 globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv,  globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv,
     size_t *limit)      struct glob_limit *limit)
 {  {
         int     i;          int     i;
         Char   *lm, *ls;          Char   *lm, *ls;
Line 341  globexp2(const Char *ptr, const Char *pa
Line 356  globexp2(const Char *ptr, const Char *pa
   
                                 /* Expand the current pattern */                                  /* Expand the current pattern */
 #ifdef DEBUG  #ifdef DEBUG
                                 qprintf("globexp2:", patbuf);                                  qprintf("globexp2", patbuf);
 #endif  #endif
                                 *rv = globexp1(patbuf, pglob, limit);                                  *rv = globexp1(patbuf, pglob, limit);
   
Line 456  globtilde(const Char *pattern, Char *pat
Line 471  globtilde(const Char *pattern, Char *pat
  * to find no matches.   * to find no matches.
  */   */
 static int  static int
 glob0(const Char *pattern, glob_t *pglob, size_t *limit)  glob0(const Char *pattern, glob_t *pglob, struct glob_limit *limit)
 {  {
         const Char *qpatnext;          const Char *qpatnext;
         int c, error;          int c, error;
Line 508  glob0(const Char *pattern, glob_t *pglob
Line 523  glob0(const Char *pattern, glob_t *pglob
                         break;                          break;
                 case STAR:                  case STAR:
                         pglob->gl_flags |= GLOB_MAGCHAR;                          pglob->gl_flags |= GLOB_MAGCHAR;
                         /* collapse adjacent stars to one,                          /* collapse adjacent stars to one [or three if globstar]
                          * to avoid exponential behavior                           * to avoid exponential behavior
                          */                           */
                         if (bufnext == patbuf || bufnext[-1] != M_ALL)                          if (bufnext == patbuf || bufnext[-1] != M_ALL ||
                               ((pglob->gl_flags & GLOB_STAR) != 0 &&
                               (bufnext - 1 == patbuf || bufnext[-2] != M_ALL ||
                               bufnext - 2 == patbuf || bufnext[-3] != M_ALL)))
                                 *bufnext++ = M_ALL;                                  *bufnext++ = M_ALL;
                         break;                          break;
                 default:                  default:
Line 521  glob0(const Char *pattern, glob_t *pglob
Line 539  glob0(const Char *pattern, glob_t *pglob
         }          }
         *bufnext = EOS;          *bufnext = EOS;
 #ifdef DEBUG  #ifdef DEBUG
         qprintf("glob0:", patbuf);          qprintf("glob0", patbuf);
 #endif  #endif
   
         if ((error = glob1(patbuf, pglob, limit)) != 0)          if ((error = glob1(patbuf, pglob, limit)) != 0)
Line 562  compare(const void *p, const void *q)
Line 580  compare(const void *p, const void *q)
 }  }
   
 static int  static int
 glob1(Char *pattern, glob_t *pglob, size_t *limit)  glob1(Char *pattern, glob_t *pglob, struct glob_limit *limit)
 {  {
         Char pathbuf[MAXPATHLEN+1];          Char pathbuf[MAXPATHLEN+1];
   
Line 587  glob1(Char *pattern, glob_t *pglob, size
Line 605  glob1(Char *pattern, glob_t *pglob, size
  * meta characters.   * meta characters.
  */   */
 static int  static int
 glob2(Char *pathbuf, Char *pathend, Char *pathlim, Char *pattern, glob_t *pglob,  glob2(Char *pathbuf, Char *pathend, Char *pathlim, const Char *pattern,
     size_t *limit)      glob_t *pglob, struct glob_limit *limit)
 {  {
         __gl_stat_t sb;          __gl_stat_t sb;
         Char *p, *q;          const Char *p;
           Char *q;
         int anymeta;          int anymeta;
   
         _DIAGASSERT(pathbuf != NULL);          _DIAGASSERT(pathbuf != NULL);
Line 599  glob2(Char *pathbuf, Char *pathend, Char
Line 618  glob2(Char *pathbuf, Char *pathend, Char
         _DIAGASSERT(pattern != NULL);          _DIAGASSERT(pattern != NULL);
         _DIAGASSERT(pglob != NULL);          _DIAGASSERT(pglob != NULL);
   
   #ifdef DEBUG
           qprintf("glob2", pathbuf);
   #endif
         /*          /*
          * Loop over pattern segments until end of pattern or until           * Loop over pattern segments until end of pattern or until
          * segment with meta character found.           * segment with meta character found.
Line 610  glob2(Char *pathbuf, Char *pathend, Char
Line 632  glob2(Char *pathbuf, Char *pathend, Char
                                 return 0;                                  return 0;
   
                         if ((pglob->gl_flags & GLOB_LIMIT) &&                          if ((pglob->gl_flags & GLOB_LIMIT) &&
                             limit[GLOB_INDEX_STAT]++ >= GLOB_LIMIT_STAT) {                              limit->l_stat++ >= GLOB_LIMIT_STAT) {
                                 errno = 0;                                  errno = 0;
                                 *pathend++ = SEP;                                  *pathend++ = SEP;
                                 *pathend = EOS;                                  *pathend = EOS;
Line 641  glob2(Char *pathbuf, Char *pathend, Char
Line 663  glob2(Char *pathbuf, Char *pathend, Char
                         *q++ = *p++;                          *q++ = *p++;
                 }                  }
   
                 if (!anymeta) {         /* No expansion, do next segment. */                  if (!anymeta) {
                         pathend = q;                          pathend = q;
                         pattern = p;                          pattern = p;
                         while (*pattern == SEP) {                          while (*pattern == SEP) {
Line 651  glob2(Char *pathbuf, Char *pathend, Char
Line 673  glob2(Char *pathbuf, Char *pathend, Char
                         }                          }
                 } else                  /* Need expansion, recurse. */                  } else                  /* Need expansion, recurse. */
                         return glob3(pathbuf, pathend, pathlim, pattern, p,                          return glob3(pathbuf, pathend, pathlim, pattern, p,
                             pglob, limit);                              pattern, pglob, limit);
         }          }
         /* NOTREACHED */          /* NOTREACHED */
 }  }
   
 static int  static int
 glob3(Char *pathbuf, Char *pathend, Char *pathlim, Char *pattern,  glob3(Char *pathbuf, Char *pathend, Char *pathlim, const Char *pattern,
     Char *restpattern, glob_t *pglob, size_t *limit)      const Char *restpattern, const Char *pglobstar, glob_t *pglob,
       struct glob_limit *limit)
 {  {
         struct dirent *dp;          struct dirent *dp;
         DIR *dirp;          DIR *dirp;
           __gl_stat_t sbuf;
         int error;          int error;
         char buf[MAXPATHLEN];          char buf[MAXPATHLEN];
           int globstar = 0;
           int chase_symlinks = 0;
           const Char *termstar = NULL;
   
         /*          /*
          * The readdirfunc declaration can't be prototyped, because it is           * The readdirfunc declaration can't be prototyped, because it is
Line 682  glob3(Char *pathbuf, Char *pathend, Char
Line 709  glob3(Char *pathbuf, Char *pathend, Char
         *pathend = EOS;          *pathend = EOS;
         errno = 0;          errno = 0;
   
           while (pglobstar < restpattern) {
                   if ((pglobstar[0] & M_MASK) == M_ALL &&
                       (pglobstar[1] & M_MASK) == M_ALL) {
                           globstar = 1;
                           chase_symlinks = (pglobstar[2] & M_MASK) == M_ALL;
                           termstar = pglobstar + (2 + chase_symlinks);
                           break;
                   }
                   pglobstar++;
           }
   
           if (globstar) {
                   error = pglobstar == pattern && termstar == restpattern ?
                       *restpattern == EOS ?
                       glob2(pathbuf, pathend, pathlim, restpattern - 1, pglob,
                       limit) :
                       glob2(pathbuf, pathend, pathlim, restpattern + 1, pglob,
                       limit) :
                       glob3(pathbuf, pathend, pathlim, pattern, restpattern,
                       termstar, pglob, limit);
                   if (error)
                           return error;
                   *pathend = EOS;
           }
   
           if (*pathbuf && (g_lstat(pathbuf, &sbuf, pglob) ||
               !S_ISDIR(sbuf.st_mode)
   #ifdef S_IFLINK
                && ((globstar && !chase_symlinks) || !S_ISLNK(sbuf.st_mode))
   #endif
               ))
                   return 0;
   
         if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {          if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
                 if (pglob->gl_errfunc) {                  if (pglob->gl_errfunc) {
                         if (g_Ctoc(pathbuf, buf, sizeof(buf)))                          if (g_Ctoc(pathbuf, buf, sizeof(buf)))
Line 708  glob3(Char *pathbuf, Char *pathend, Char
Line 768  glob3(Char *pathbuf, Char *pathend, Char
         if (pglob->gl_flags & GLOB_ALTDIRFUNC)          if (pglob->gl_flags & GLOB_ALTDIRFUNC)
                 readdirfunc = pglob->gl_readdir;                  readdirfunc = pglob->gl_readdir;
         else          else
                 readdirfunc = (struct dirent *(*)__P((void *))) readdir;                  readdirfunc = (struct dirent *(*)(void *)) readdir;
         while ((dp = (*readdirfunc)(dirp)) != NULL) {          while ((dp = (*readdirfunc)(dirp)) != NULL) {
                 u_char *sc;                  unsigned char *sc;
                 Char *dc;                  Char *dc;
   
                 /* Initial DOT must be matched literally. */                  if ((pglob->gl_flags & GLOB_LIMIT) &&
                 if (dp->d_name[0] == DOT && *pattern != DOT)                      limit->l_readdir++ >= GLOB_LIMIT_READDIR) {
                           errno = 0;
                           *pathend++ = SEP;
                           *pathend = EOS;
                           error = GLOB_NOSPACE;
                           break;
                   }
   
                   /*
                    * Initial DOT must be matched literally, unless we have
                    * GLOB_PERIOD set.
                    */
                   if ((pglob->gl_flags & GLOB_PERIOD) == 0)
                           if (dp->d_name[0] == DOT && *pattern != DOT)
                                   continue;
                   /*
                    * If GLOB_NO_DOTDIRS is set, . and .. vanish.
                    */
                   if ((pglob->gl_flags & GLOB_NO_DOTDIRS) &&
                       (dp->d_name[0] == DOT) &&
                       ((dp->d_name[1] == EOS) ||
                        ((dp->d_name[1] == DOT) && (dp->d_name[2] == EOS))))
                         continue;                          continue;
                 /*                  /*
                  * The resulting string contains EOS, so we can                   * The resulting string contains EOS, so we can
                  * use the pathlim character, if it is the nul                   * use the pathlim character, if it is the nul
                  */                   */
                 for (sc = (u_char *) dp->d_name, dc = pathend;                  for (sc = (unsigned char *) dp->d_name, dc = pathend;
                      dc <= pathlim && (*dc++ = *sc++) != EOS;)                       dc <= pathlim && (*dc++ = *sc++) != EOS;)
                         continue;                          continue;
   
                 if ((pglob->gl_flags & GLOB_LIMIT) &&  
                     limit[GLOB_INDEX_READDIR]++ >= GLOB_LIMIT_READDIR) {  
                         errno = 0;  
                         *pathend++ = SEP;  
                         *pathend = EOS;  
                         return GLOB_NOSPACE;  
                 }  
   
                 /*                  /*
                  * Have we filled the buffer without seeing EOS?                   * Have we filled the buffer without seeing EOS?
                  */                   */
Line 751  glob3(Char *pathbuf, Char *pathend, Char
Line 824  glob3(Char *pathbuf, Char *pathend, Char
                         }                          }
                 }                  }
   
                 if (!match(pathend, pattern, restpattern)) {                  if (globstar) {
   #ifdef S_IFLNK
                           if (!chase_symlinks &&
                               (g_lstat(pathbuf, &sbuf, pglob) ||
                               S_ISLNK(sbuf.st_mode)))
                                   continue;
   #endif
   
                           if (!match(pathend, pattern, termstar))
                                   continue;
   
                           if (--dc < pathlim - 2)
                                   *dc++ = SEP;
                           *dc = EOS;
                           error = glob2(pathbuf, dc, pathlim, pglobstar,
                               pglob, limit);
                           if (error)
                                   break;
                         *pathend = EOS;                          *pathend = EOS;
                         continue;                  } else {
                           if (!match(pathend, pattern, restpattern)) {
                                   *pathend = EOS;
                                   continue;
                           }
                           error = glob2(pathbuf, --dc, pathlim, restpattern,
                               pglob, limit);
                           if (error)
                                   break;
                 }                  }
                 error = glob2(pathbuf, --dc, pathlim, restpattern, pglob,  
                     limit);  
                 if (error)  
                         break;  
         }          }
   
         if (pglob->gl_flags & GLOB_ALTDIRFUNC)          if (pglob->gl_flags & GLOB_ALTDIRFUNC)
                 (*pglob->gl_closedir)(dirp);                  (*pglob->gl_closedir)(dirp);
         else          else
Line 791  glob3(Char *pathbuf, Char *pathend, Char
Line 884  glob3(Char *pathbuf, Char *pathend, Char
  *      gl_pathv points to (gl_offs + gl_pathc + 1) items.   *      gl_pathv points to (gl_offs + gl_pathc + 1) items.
  */   */
 static int  static int
 globextend(const Char *path, glob_t *pglob, size_t *limit)  globextend(const Char *path, glob_t *pglob, struct glob_limit *limit)
 {  {
         char **pathv;          char **pathv;
         size_t i, newsize, len;          size_t i, newsize, len;
Line 802  globextend(const Char *path, glob_t *pgl
Line 895  globextend(const Char *path, glob_t *pgl
         _DIAGASSERT(pglob != NULL);          _DIAGASSERT(pglob != NULL);
   
         newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);          newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
           if ((pglob->gl_flags & GLOB_LIMIT) &&
               newsize > GLOB_LIMIT_PATH * sizeof(*pathv))
                   goto nospace;
         pathv = pglob->gl_pathv ? realloc(pglob->gl_pathv, newsize) :          pathv = pglob->gl_pathv ? realloc(pglob->gl_pathv, newsize) :
             malloc(newsize);              malloc(newsize);
         if (pathv == NULL)          if (pathv == NULL)
Line 818  globextend(const Char *path, glob_t *pgl
Line 914  globextend(const Char *path, glob_t *pgl
         for (p = path; *p++;)          for (p = path; *p++;)
                 continue;                  continue;
         len = (size_t)(p - path);          len = (size_t)(p - path);
         limit[GLOB_INDEX_MALLOC] += len;          limit->l_string += len;
         if ((copy = malloc(len)) != NULL) {          if ((copy = malloc(len)) != NULL) {
                 if (g_Ctoc(path, copy, len)) {                  if (g_Ctoc(path, copy, len)) {
                         free(copy);                          free(copy);
Line 829  globextend(const Char *path, glob_t *pgl
Line 925  globextend(const Char *path, glob_t *pgl
         pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;          pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
   
         if ((pglob->gl_flags & GLOB_LIMIT) &&          if ((pglob->gl_flags & GLOB_LIMIT) &&
             (newsize + limit[GLOB_INDEX_MALLOC]) >= GLOB_LIMIT_MALLOC) {              (newsize + limit->l_string) >= GLOB_LIMIT_STRING)
                 errno = 0;                  goto nospace;
                 return GLOB_NOSPACE;  
         }  
   
         return copy == NULL ? GLOB_NOSPACE : 0;          return copy == NULL ? GLOB_NOSPACE : 0;
   nospace:
           errno = 0;
           return GLOB_NOSPACE;
 }  }
   
   
Line 843  globextend(const Char *path, glob_t *pgl
Line 940  globextend(const Char *path, glob_t *pgl
  * pattern causes a recursion level.   * pattern causes a recursion level.
  */   */
 static int  static int
 match(Char *name, Char *pat, Char *patend)  match(const Char *name, const Char *pat, const Char *patend)
 {  {
         int ok, negate_range;          int ok, negate_range;
         Char c, k;          Char c, k;
Line 856  match(Char *name, Char *pat, Char *paten
Line 953  match(Char *name, Char *pat, Char *paten
                 c = *pat++;                  c = *pat++;
                 switch (c & M_MASK) {                  switch (c & M_MASK) {
                 case M_ALL:                  case M_ALL:
                           while (pat < patend && (*pat & M_MASK) == M_ALL)
                                   pat++;  /* eat consecutive '*' */
                         if (pat == patend)                          if (pat == patend)
                                 return 1;                                  return 1;
                         do                          for (; !match(name, pat, patend); name++)
                             if (match(name, pat, patend))                                  if (*name == EOS)
                                     return 1;                                          return 0;
                         while (*name++ != EOS);                          return 1;
                         return 0;  
                 case M_ONE:                  case M_ONE:
                         if (*name++ == EOS)                          if (*name++ == EOS)
                                 return 0;                                  return 0;
Line 912  globfree(glob_t *pglob)
Line 1010  globfree(glob_t *pglob)
         }          }
 }  }
   
   #ifndef __LIBC12_SOURCE__
   int
   glob_pattern_p(const char *pattern, int quote)
   {
           int range = 0;
   
           for (; *pattern; pattern++)
                   switch (*pattern) {
                   case QUESTION:
                   case STAR:
                           return 1;
   
                   case QUOTE:
                           if (quote && pattern[1] != EOS)
                                 ++pattern;
                           break;
   
                   case LBRACKET:
                           range = 1;
                           break;
   
                   case RBRACKET:
                           if (range)
                                 return 1;
                           break;
                   default:
                           break;
                   }
   
             return 0;
   }
   #endif
   
 static DIR *  static DIR *
 g_opendir(Char *str, glob_t *pglob)  g_opendir(Char *str, glob_t *pglob)
 {  {

Legend:
Removed from v.1.18.2.1  
changed lines
  Added in v.1.31.2.1

CVSweb <webmaster@jp.NetBSD.org>