OSDN Git Service

2009-09-23 Matthew Gingell <gingell@adacore.com>
[pf3gnuchains/gcc-fork.git] / libiberty / fnmatch.c
index 685d9e4..fc897be 100644 (file)
@@ -1,7 +1,7 @@
 /* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
 
-NOTE: The canonical source of this file is maintained with the GNU C Library.
-Bugs can be reported to bug-glibc@prep.ai.mit.edu.
+NOTE: This source is derived from an old version taken from the GNU C
+Library (glibc).
 
 This program is free software; you can redistribute it and/or modify it
 under the terms of the GNU General Public License as published by the
@@ -15,7 +15,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
-Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Foundation, 51 Franklin Street - Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 #ifdef HAVE_CONFIG_H
 #if defined (CONFIG_BROKETS)
@@ -44,8 +45,7 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include <errno.h>
 #include <fnmatch.h>
-#include <ctype.h>
-
+#include <safe-ctype.h>
 
 /* Comment out all this code if we are using the GNU C Library, and are not
    actually compiling the library itself.  This code is part of the GNU C
@@ -65,16 +65,12 @@ extern int errno;
 /* Match STRING against the filename pattern PATTERN, returning zero if
    it matches, nonzero if not.  */
 int
-fnmatch (pattern, string, flags)
-     const char *pattern;
-     const char *string;
-     int flags;
+fnmatch (const char *pattern, const char *string, int flags)
 {
   register const char *p = pattern, *n = string;
-  register char c;
+  register unsigned char c;
 
-/* Note that this evalutes C many times.  */
-#define FOLD(c)        ((flags & FNM_CASEFOLD) && isupper (c) ? tolower (c) : (c))
+#define FOLD(c)        ((flags & FNM_CASEFOLD) ? TOLOWER (c) : (c))
 
   while ((c = *p++) != '\0')
     {
@@ -98,7 +94,7 @@ fnmatch (pattern, string, flags)
              c = *p++;
              c = FOLD (c);
            }
-         if (FOLD (*n) != c)
+         if (FOLD ((unsigned char)*n) != c)
            return FNM_NOMATCH;
          break;
 
@@ -116,10 +112,10 @@ fnmatch (pattern, string, flags)
            return 0;
 
          {
-           char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
+           unsigned char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
            c1 = FOLD (c1);
            for (--p; *n != '\0'; ++n)
-             if ((c == '[' || FOLD (*n) == c1) &&
+             if ((c == '[' || FOLD ((unsigned char)*n) == c1) &&
                  fnmatch (p, n, flags & ~FNM_PERIOD) == 0)
                return 0;
            return FNM_NOMATCH;
@@ -128,7 +124,7 @@ fnmatch (pattern, string, flags)
        case '[':
          {
            /* Nonzero if the sense of the character class is inverted.  */
-           register int not;
+           register int negate;
 
            if (*n == '\0')
              return FNM_NOMATCH;
@@ -137,14 +133,14 @@ fnmatch (pattern, string, flags)
                (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
              return FNM_NOMATCH;
 
-           not = (*p == '!' || *p == '^');
-           if (not)
+           negate = (*p == '!' || *p == '^');
+           if (negate)
              ++p;
 
            c = *p++;
            for (;;)
              {
-               register char cstart = c, cend = c;
+               register unsigned char cstart = c, cend = c;
 
                if (!(flags & FNM_NOESCAPE) && c == '\\')
                  cstart = cend = *p++;
@@ -174,13 +170,14 @@ fnmatch (pattern, string, flags)
                    c = *p++;
                  }
 
-               if (FOLD (*n) >= cstart && FOLD (*n) <= cend)
+               if (FOLD ((unsigned char)*n) >= cstart
+                   && FOLD ((unsigned char)*n) <= cend)
                  goto matched;
 
                if (c == ']')
                  break;
              }
-           if (!not)
+           if (!negate)
              return FNM_NOMATCH;
            break;
 
@@ -197,13 +194,13 @@ fnmatch (pattern, string, flags)
                  /* XXX 1003.2d11 is unclear if this is right.  */
                  ++p;
              }
-           if (not)
+           if (negate)
              return FNM_NOMATCH;
          }
          break;
 
        default:
-         if (c != FOLD (*n))
+         if (c != FOLD ((unsigned char)*n))
            return FNM_NOMATCH;
        }