GNU file utilities
[gnulib.git] / lib / fnmatch.c
index be662d9..df1706c 100644 (file)
@@ -15,10 +15,33 @@ License along with this library; see the file COPYING.LIB.  If
 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
 Cambridge, MA 02139, USA.  */
 
+#ifdef HAVE_CONFIG_H
+#if defined (CONFIG_BROKETS)
+/* We use <config.h> instead of "config.h" so that a compilation
+   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
+   (which it would do because it found this file in $srcdir).  */
+#include <config.h>
+#else
+#include "config.h"
+#endif
+#endif
+
 #include <errno.h>
 #include <fnmatch.h>
 #include <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
+   Library, but also included in many other GNU distributions.  Compiling
+   and linking in this code is a waste when using the GNU C library
+   (especially if it is a shared library).  Rather than having every GNU
+   program understand `configure --with-gnu-libc' and omit the object files,
+   it is simpler to just do this in the source for each such file.  */
+
+#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
+
+
 #if !defined(__GNU_LIBRARY__) && !defined(STDC_HEADERS)
 extern int errno;
 #endif
@@ -77,7 +100,8 @@ fnmatch (pattern, string, flags)
            return 0;
 
          {
-           char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? FOLD (*p) : c;
+           char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
+           c1 = FOLD (c1);
            for (--p; *n != '\0'; ++n)
              if ((c == '[' || FOLD (*n) == c1) &&
                  fnmatch (p, n, flags & ~FNM_PERIOD) == 0)
@@ -179,3 +203,5 @@ fnmatch (pattern, string, flags)
 
   return FNM_NOMATCH;
 }
+
+#endif /* _LIBC or not __GNU_LIBRARY__.  */