diff options
author | wosch <wosch@FreeBSD.org> | 1996-10-20 15:15:59 +0000 |
---|---|---|
committer | wosch <wosch@FreeBSD.org> | 1996-10-20 15:15:59 +0000 |
commit | 085d68ca3b32f461a9696ba337611b65e7a3e6a2 (patch) | |
tree | cbf6549406ce42722ca5e0d1481813434f5baef6 /lib | |
parent | f19270888a2f8551c7569b1b0875fee211db0f40 (diff) | |
download | FreeBSD-src-085d68ca3b32f461a9696ba337611b65e7a3e6a2.zip FreeBSD-src-085d68ca3b32f461a9696ba337611b65e7a3e6a2.tar.gz |
add flag FNM_ICASE for case insensitve search
Reviewed by: ache
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/fnmatch.3 | 5 | ||||
-rw-r--r-- | lib/libc/gen/fnmatch.c | 21 |
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/libc/gen/fnmatch.3 b/lib/libc/gen/fnmatch.3 index d533e09..4363426 100644 --- a/lib/libc/gen/fnmatch.3 +++ b/lib/libc/gen/fnmatch.3 @@ -99,6 +99,11 @@ Additionally, if .Dv FNM_PATHNAME is set, a period is ``leading'' if it immediately follows a slash. +.It Dv FNM_ICASE +Ignore case distinctions in both the +.Fa pattern +and the +.Fa string . .El .Sh RETURN VALUES The diff --git a/lib/libc/gen/fnmatch.c b/lib/libc/gen/fnmatch.c index 47bd405..1fa1db5 100644 --- a/lib/libc/gen/fnmatch.c +++ b/lib/libc/gen/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 ) |