1 /* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
3 This library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Library General Public License as
5 published by the Free Software Foundation; either version 2 of the
6 License, or (at your option) any later version.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public
14 License along with this library; see the file COPYING.LIB. If
15 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
16 Cambridge, MA 02139, USA. */
19 #if defined (CONFIG_BROKETS)
20 /* We use <config.h> instead of "config.h" so that a compilation
21 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
22 (which it would do because it found this file in $srcdir). */
34 /* Comment out all this code if we are using the GNU C Library, and are not
35 actually compiling the library itself. This code is part of the GNU C
36 Library, but also included in many other GNU distributions. Compiling
37 and linking in this code is a waste when using the GNU C library
38 (especially if it is a shared library). Rather than having every GNU
39 program understand `configure --with-gnu-libc' and omit the object files,
40 it is simpler to just do this in the source for each such file. */
42 #if defined (_LIBC) || !defined (__GNU_LIBRARY__)
45 #if !defined(__GNU_LIBRARY__) && !defined(STDC_HEADERS)
49 /* Match STRING against the filename pattern PATTERN, returning zero if
50 it matches, nonzero if not. */
52 fnmatch (pattern, string, flags)
57 register const char *p = pattern, *n = string;
60 /* Note that this evalutes C many times. */
61 #define FOLD(c) ((flags & FNM_CASEFOLD) && isupper (c) ? tolower (c) : (c))
63 while ((c = *p++) != '\0')
72 else if ((flags & FNM_FILE_NAME) && *n == '/')
74 else if ((flags & FNM_PERIOD) && *n == '.' &&
75 (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
80 if (!(flags & FNM_NOESCAPE))
90 if ((flags & FNM_PERIOD) && *n == '.' &&
91 (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
94 for (c = *p++; c == '?' || c == '*'; c = *p++, ++n)
95 if (((flags & FNM_FILE_NAME) && *n == '/') ||
96 (c == '?' && *n == '\0'))
103 char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
105 for (--p; *n != '\0'; ++n)
106 if ((c == '[' || FOLD (*n) == c1) &&
107 fnmatch (p, n, flags & ~FNM_PERIOD) == 0)
114 /* Nonzero if the sense of the character class is inverted. */
120 if ((flags & FNM_PERIOD) && *n == '.' &&
121 (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
124 not = (*p == '!' || *p == '^');
131 register char cstart = c, cend = c;
133 if (!(flags & FNM_NOESCAPE) && c == '\\')
134 cstart = cend = *p++;
136 cstart = cend = FOLD (cstart);
139 /* [ (unterminated) loses. */
145 if ((flags & FNM_FILE_NAME) && c == '/')
146 /* [/] can never match. */
149 if (c == '-' && *p != ']')
152 if (!(flags & FNM_NOESCAPE) && cend == '\\')
161 if (FOLD (*n) >= cstart && FOLD (*n) <= cend)
172 /* Skip the rest of the [...] that already matched. */
176 /* [... (unterminated) loses. */
180 if (!(flags & FNM_NOESCAPE) && c == '\\')
181 /* XXX 1003.2d11 is unclear if this is right. */
200 if ((flags & FNM_LEADING_DIR) && *n == '/')
201 /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
207 #endif /* _LIBC or not __GNU_LIBRARY__. */