/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
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. */
#if !defined(__GNU_LIBRARY__) && !defined(STDC_HEADERS)
/* Match STRING against the filename pattern PATTERN, returning zero if
it matches, nonzero if not. */
fnmatch (pattern
, string
, flags
)
register const char *p
= pattern
, *n
= string
;
if ((flags
& ~__FNM_FLAGS
) != 0)
while ((c
= *p
++) != '\0')
else if ((flags
& FNM_PATHNAME
) && *n
== '/')
else if ((flags
& FNM_PERIOD
) && *n
== '.' &&
(n
== string
|| ((flags
& FNM_PATHNAME
) && n
[-1] == '/')))
if (!(flags
& FNM_NOESCAPE
))
if ((flags
& FNM_PERIOD
) && *n
== '.' &&
(n
== string
|| ((flags
& FNM_PATHNAME
) && n
[-1] == '/')))
for (c
= *p
++; c
== '?' || c
== '*'; c
= *p
++, ++n
)
if (((flags
& FNM_PATHNAME
) && *n
== '/') ||
(c
== '?' && *n
== '\0'))
char c1
= (!(flags
& FNM_NOESCAPE
) && c
== '\\') ? *p
: c
;
for (--p
; *n
!= '\0'; ++n
)
if ((c
== '[' || *n
== c1
) &&
fnmatch (p
, n
, flags
& ~FNM_PERIOD
) == 0)
/* Nonzero if the sense of the character class is inverted. */
if ((flags
& FNM_PERIOD
) && *n
== '.' &&
(n
== string
|| ((flags
& FNM_PATHNAME
) && n
[-1] == '/')))
not = (*p
== '!' || *p
== '^');
register char cstart
= c
, cend
= c
;
if (!(flags
& FNM_NOESCAPE
) && c
== '\\')
/* [ (unterminated) loses. */
if ((flags
& FNM_PATHNAME
) && c
== '/')
/* [/] can never match. */
if (c
== '-' && *p
!= ']')
if (!(flags
& FNM_NOESCAPE
) && cend
== '\\')
if (*n
>= cstart
&& *n
<= cend
)
/* Skip the rest of the [...] that already matched. */
/* [... (unterminated) loses. */
if (!(flags
& FNM_NOESCAPE
) && c
== '\\')
/* 1003.2d11 is unclear if this is right. %%% */
if ((flags
& FNM_LEADING_DIR
) && *n
== '/')
/* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */