From 63f3cf925bcaa8ea3bcfa63800bc52d581c40bcc Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sat, 22 Jun 1996 21:14:22 +0000 Subject: Updated from libc --- glob/fnmatch.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'glob/fnmatch.c') diff --git a/glob/fnmatch.c b/glob/fnmatch.c index 08c1c94..de45941 100644 --- a/glob/fnmatch.c +++ b/glob/fnmatch.c @@ -92,10 +92,24 @@ fnmatch (pattern, string, flags) (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/'))) return FNM_NOMATCH; - for (c = *p++; c == '?' || c == '*'; c = *p++, ++n) - if (((flags & FNM_FILE_NAME) && *n == '/') || - (c == '?' && *n == '\0')) - return FNM_NOMATCH; + for (c = *p++; c == '?' || c == '*'; c = *p++) + { + if ((flags & FNM_FILE_NAME) && *n == '/') + /* A slash does not match a wildcard under FNM_FILE_NAME. */ + return FNM_NOMATCH; + else if (c == '?') + { + /* A ? needs to match one character. */ + if (*n == '\0') + /* There isn't another character; no match. */ + return FNM_NOMATCH; + else + /* One character of the string is consumed in matching + this ? wildcard, so *??? won't match if there are + less than three characters. */ + ++n; + } + } if (c == '\0') return 0; -- cgit v1.2.3