[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.31.8.2 and 1.32

version 1.31.8.2, 2013/06/23 06:21:05 version 1.32, 2012/12/18 01:39:56
Line 132  struct glob_limit {
Line 132  struct glob_limit {
 #define M_MASK          0xffff  #define M_MASK          0xffff
 #define M_ASCII         0x00ff  #define M_ASCII         0x00ff
   
 typedef unsigned short Char;  typedef u_short Char;
   
 #else  #else
   
Line 163  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 *, struct glob_limit *);  static int       glob0(const char *, const Char *, glob_t *, struct glob_limit *);
 static int       glob1(Char *, glob_t *, struct glob_limit *);  static int       glob1(Char *, glob_t *, struct glob_limit *);
 static int       glob2(Char *, Char *, Char *, const Char *, glob_t *,  static int       glob2(Char *, Char *, Char *, const Char *, glob_t *,
     struct glob_limit *);      struct glob_limit *);
Line 171  static int  glob3(Char *, Char *, Char *
Line 171  static int  glob3(Char *, Char *, Char *
     const Char *, glob_t *, struct glob_limit *);      const Char *, glob_t *, struct glob_limit *);
 static int       globextend(const Char *, glob_t *, struct glob_limit *);  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 *, struct glob_limit *);  static int       globexp1(const char *, const Char *, glob_t *, struct glob_limit *);
 static int       globexp2(const Char *, const Char *, glob_t *, int *,  static int       globexp2(const char *, const Char *, const Char *, glob_t *, int *,
     struct glob_limit *);      struct glob_limit *);
 static int       match(const Char *, const Char *, const Char *);  static int       match(const Char *, const Char *, const Char *);
 #ifdef DEBUG  #ifdef DEBUG
Line 183  int
Line 183  int
 glob(const char * __restrict pattern, int flags, int (*errfunc)(const char *,  glob(const char * __restrict pattern, int flags, int (*errfunc)(const char *,
     int), glob_t * __restrict pglob)      int), glob_t * __restrict pglob)
 {  {
         const unsigned char *patnext;          const u_char *patnext;
         int c;          int c;
         Char *bufnext, *bufend, patbuf[MAXPATHLEN+1];          Char *bufnext, *bufend, patbuf[MAXPATHLEN+1];
         struct glob_limit limit = { 0, 0, 0, 0 };          struct glob_limit limit = { 0, 0, 0, 0 };
   
         _DIAGASSERT(pattern != NULL);          _DIAGASSERT(pattern != NULL);
   
         patnext = (const unsigned char *) pattern;          patnext = (const u_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 222  glob(const char * __restrict pattern, in
Line 222  glob(const char * __restrict pattern, in
         *bufnext = EOS;          *bufnext = EOS;
   
         if (flags & GLOB_BRACE)          if (flags & GLOB_BRACE)
             return globexp1(patbuf, pglob, &limit);              return globexp1(pattern, patbuf, pglob, &limit);
         else          else
             return glob0(patbuf, pglob, &limit);              return glob0(pattern, patbuf, pglob, &limit);
 }  }
   
 /*  /*
Line 233  glob(const char * __restrict pattern, in
Line 233  glob(const char * __restrict pattern, in
  * characters   * characters
  */   */
 static int  static int
 globexp1(const Char *pattern, glob_t *pglob, struct glob_limit *limit)  globexp1(const char *orig, const Char *pattern, glob_t *pglob, struct glob_limit *limit)
 {  {
         const Char* ptr = pattern;          const Char* ptr = pattern;
         int rv;          int rv;
Line 249  globexp1(const Char *pattern, glob_t *pg
Line 249  globexp1(const Char *pattern, glob_t *pg
   
         /* 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(orig, pattern, pglob, limit);
   
         while ((ptr = (const Char *) g_strchr(ptr, LBRACE)) != NULL)          while ((ptr = (const Char *) g_strchr(ptr, LBRACE)) != NULL)
                 if (!globexp2(ptr, pattern, pglob, &rv, limit))                  if (!globexp2(orig, ptr, pattern, pglob, &rv, limit))
                         return rv;                          return rv;
   
         return glob0(pattern, pglob, limit);          return glob0(orig, pattern, pglob, limit);
 }  }
   
   
Line 265  globexp1(const Char *pattern, glob_t *pg
Line 265  globexp1(const Char *pattern, glob_t *pg
  * If it fails then it tries to glob the rest of the pattern and returns.   * If it fails then it tries to glob the rest of the pattern and returns.
  */   */
 static int  static int
 globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv,  globexp2(const char *orig, const Char *ptr, const Char *pattern, glob_t *pglob, int *rv,
     struct glob_limit *limit)      struct glob_limit *limit)
 {  {
         int     i;          int     i;
Line 311  globexp2(const Char *ptr, const Char *pa
Line 311  globexp2(const Char *ptr, const Char *pa
                  * we use `pattern', not `patbuf' here so that that                   * we use `pattern', not `patbuf' here so that that
                  * unbalanced braces are passed to the match                   * unbalanced braces are passed to the match
                  */                   */
                 *rv = glob0(pattern, pglob, limit);                  *rv = glob0(orig, pattern, pglob, limit);
                 return 0;                  return 0;
         }          }
   
Line 358  globexp2(const Char *ptr, const Char *pa
Line 358  globexp2(const Char *ptr, const Char *pa
 #ifdef DEBUG  #ifdef DEBUG
                                 qprintf("globexp2", patbuf);                                  qprintf("globexp2", patbuf);
 #endif  #endif
                                 *rv = globexp1(patbuf, pglob, limit);                                  *rv = globexp1(orig, patbuf, pglob, limit);
   
                                 /* move after the comma, to the next string */                                  /* move after the comma, to the next string */
                                 pl = pm + 1;                                  pl = pm + 1;
Line 471  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, struct glob_limit *limit)  glob0(const char *orig, const Char *pattern, glob_t *pglob, struct glob_limit *limit)
 {  {
         const Char *qpatnext;          const Char *qpatnext;
         int c, error;          int c, error;
Line 556  glob0(const Char *pattern, glob_t *pglob
Line 556  glob0(const Char *pattern, glob_t *pglob
                 if ((pglob->gl_flags & GLOB_NOCHECK) ||                  if ((pglob->gl_flags & GLOB_NOCHECK) ||
                     ((pglob->gl_flags & (GLOB_NOMAGIC|GLOB_MAGCHAR))                      ((pglob->gl_flags & (GLOB_NOMAGIC|GLOB_MAGCHAR))
                      == GLOB_NOMAGIC)) {                       == GLOB_NOMAGIC)) {
                         return globextend(pattern, pglob, limit);                          const u_char *patnext;
                           Char *bufend;
                           bufend = patbuf + MAXPATHLEN;
                           patnext = (const unsigned char *)orig;
                           bufnext = patbuf;
                           while (bufnext < bufend && (c = *patnext++) != EOS)
                                   *bufnext++ = c;
   
                           *bufnext = EOS;
   
                           return globextend(patbuf, pglob, limit);
                 } else {                  } else {
                         return GLOB_NOMATCH;                          return GLOB_NOMATCH;
                 }                  }
Line 612  glob2(Char *pathbuf, Char *pathend, Char
Line 622  glob2(Char *pathbuf, Char *pathend, Char
         const Char *p;          const Char *p;
         Char *q;          Char *q;
         int anymeta;          int anymeta;
           Char *pend;
           ptrdiff_t diff;
   
         _DIAGASSERT(pathbuf != NULL);          _DIAGASSERT(pathbuf != NULL);
         _DIAGASSERT(pathend != NULL);          _DIAGASSERT(pathend != NULL);
Line 663  glob2(Char *pathbuf, Char *pathend, Char
Line 675  glob2(Char *pathbuf, Char *pathend, Char
                         *q++ = *p++;                          *q++ = *p++;
                 }                  }
   
                 if (!anymeta) {                  /*
                    * No expansion, or path ends in slash-dot shash-dot-dot,
                    * do next segment.
                    */
                   if (pglob->gl_flags & GLOB_PERIOD) {
                           for (pend = pathend; pend > pathbuf && pend[-1] == '/';
                               pend--)
                                   continue;
                           diff = pend - pathbuf;
                   } else {
                           /* XXX: GCC */
                           diff = 0;
                           pend = pathend;
                   }
   
                   if ((!anymeta) ||
                       ((pglob->gl_flags & GLOB_PERIOD) &&
                        (diff >= 1 && pend[-1] == DOT) &&
                        (diff >= 2 && (pend[-2] == SLASH || pend[-2] == DOT)) &&
                        (diff < 3 || pend[-3] == SLASH))) {
                         pathend = q;                          pathend = q;
                         pattern = p;                          pattern = p;
                         while (*pattern == SEP) {                          while (*pattern == SEP) {
Line 770  glob3(Char *pathbuf, Char *pathend, Char
Line 801  glob3(Char *pathbuf, Char *pathend, Char
         else          else
                 readdirfunc = (struct dirent *(*)(void *)) readdir;                  readdirfunc = (struct dirent *(*)(void *)) readdir;
         while ((dp = (*readdirfunc)(dirp)) != NULL) {          while ((dp = (*readdirfunc)(dirp)) != NULL) {
                 unsigned char *sc;                  u_char *sc;
                 Char *dc;                  Char *dc;
   
                 if ((pglob->gl_flags & GLOB_LIMIT) &&                  if ((pglob->gl_flags & GLOB_LIMIT) &&
Line 801  glob3(Char *pathbuf, Char *pathend, Char
Line 832  glob3(Char *pathbuf, Char *pathend, Char
                  * 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 = (unsigned char *) dp->d_name, dc = pathend;                  for (sc = (u_char *) dp->d_name, dc = pathend;
                      dc <= pathlim && (*dc++ = *sc++) != EOS;)                       dc <= pathlim && (*dc++ = *sc++) != EOS;)
                         continue;                          continue;
   

Legend:
Removed from v.1.31.8.2  
changed lines
  Added in v.1.32

CVSweb <webmaster@jp.NetBSD.org>