summaryrefslogtreecommitdiffstats
path: root/sys/libkern
diff options
context:
space:
mode:
authorwosch <wosch@FreeBSD.org>1996-10-20 15:15:59 +0000
committerwosch <wosch@FreeBSD.org>1996-10-20 15:15:59 +0000
commit085d68ca3b32f461a9696ba337611b65e7a3e6a2 (patch)
treecbf6549406ce42722ca5e0d1481813434f5baef6 /sys/libkern
parentf19270888a2f8551c7569b1b0875fee211db0f40 (diff)
downloadFreeBSD-src-085d68ca3b32f461a9696ba337611b65e7a3e6a2.zip
FreeBSD-src-085d68ca3b32f461a9696ba337611b65e7a3e6a2.tar.gz
add flag FNM_ICASE for case insensitve search
Reviewed by: ache
Diffstat (limited to 'sys/libkern')
-rw-r--r--sys/libkern/fnmatch.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/sys/libkern/fnmatch.c b/sys/libkern/fnmatch.c
index 47bd405..1fa1db5 100644
--- a/sys/libkern/fnmatch.c
+++ b/sys/libkern/fnmatch.c
@@ -43,9 +43,11 @@ static char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94";
* Compares a filename or pathname to a pattern.
*/
+#include <ctype.h>
#include <fnmatch.h>
#include <locale.h>
#include <string.h>
+#include <stdio.h>
#define EOS '\0'
@@ -126,8 +128,14 @@ fnmatch(pattern, string, flags)
}
/* FALLTHROUGH */
default:
- if (c != *string++)
+ if (c == *string)
+ ;
+ else if ((flags & FNM_ICASE) &&
+ (tolower(c) == tolower(*string)))
+ ;
+ else
return (FNM_NOMATCH);
+ string++;
break;
}
/* NOTREACHED */
@@ -151,11 +159,18 @@ rangematch(pattern, test, flags)
if ( (negate = (*pattern == '!' || *pattern == '^')) )
++pattern;
+ if (flags & FNM_ICASE)
+ test = tolower(test);
+
for (ok = 0; (c = *pattern++) != ']';) {
if (c == '\\' && !(flags & FNM_NOESCAPE))
c = *pattern++;
if (c == EOS)
return (NULL);
+
+ if (flags & FNM_ICASE)
+ c = tolower(c);
+
if (*pattern == '-'
&& (c2 = *(pattern+1)) != EOS && c2 != ']') {
pattern += 2;
@@ -163,6 +178,10 @@ rangematch(pattern, test, flags)
c2 = *pattern++;
if (c2 == EOS)
return (NULL);
+
+ if (flags & FNM_ICASE)
+ c2 = tolower(c2);
+
if ( collate_range_cmp(c, test) <= 0
&& collate_range_cmp(test, c2) <= 0
)
OpenPOWER on IntegriCloud