Declare re_comp, re_exec if compiling for libc to get prototypes.
[kopensolaris-gnu/glibc.git] / posix / fnmatch.c
index 4f5c667..2d6f6af 100644 (file)
@@ -35,7 +35,7 @@
 # include <strings.h>
 #endif
 
-#ifdef STDC_HEADERS
+#if defined STDC_HEADERS || defined _LIBC
 # include <stdlib.h>
 #endif
 
@@ -216,6 +216,7 @@ fnmatch (pattern, string, flags)
            /* Nonzero if the sense of the character class is inverted.  */
            static int posixly_correct;
            register int not;
+           char cold;
 
            if (posixly_correct == 0)
              posixly_correct = getenv ("POSIXLY_CORRECT") != NULL ? 1 : -1;
@@ -227,6 +228,10 @@ fnmatch (pattern, string, flags)
                (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
              return FNM_NOMATCH;
 
+           if (*n == '/' && (flags & FNM_FILE_NAME))
+             /* `/' cannot be matched.  */
+             return FNM_NOMATCH;
+
            not = (*p == '!' || (posixly_correct < 0 && *p == '^'));
            if (not)
              ++p;
@@ -301,8 +306,23 @@ fnmatch (pattern, string, flags)
                else if (FOLD (c) == fn)
                  goto matched;
 
+               cold = c;
                c = *p++;
 
+               if (c == '-' && *p != ']')
+                 {
+                   /* It is a range.  */
+                   char cend = *p++;
+                   if (!(flags & FNM_NOESCAPE) && cend == '\\')
+                     cend = *p++;
+                   if (cend == '\0')
+                     return FNM_NOMATCH;
+
+                   if (cold <= fn && fn <= FOLD (cend))
+                     goto matched;
+
+                   c = *p++;
+                 }
                if (c == ']')
                  break;
              }