[klibc] klibc and udev
Aaron Griffin
aaronmgriffin at gmail.com
Mon Aug 14 08:43:57 PDT 2006
On 8/14/06, H. Peter Anvin <hpa at zytor.com> wrote:
> fnmatch() I'm conflicted about, because it's really typically a thin
> wrapper around the regex engine. If anyone can come up with a small
> implementation of it, though, I'm willing to take it.
how about this?
int fnmatch(const char *p, const char *s)
{
if (s[0] == '\0') {
while (p[0] == '*')
p++;
return (p[0] != '\0');
}
switch (p[0]) {
case '[':
{
int not = 0;
p++;
if (p[0] == '!') {
not = 1;
p++;
}
while ((p[0] != '\0') && (p[0] != ']')) {
int match = 0;
if (p[1] == '-') {
if ((s[0] >= p[0]) && (s[0] <= p[2]))
match = 1;
p += 3;
} else {
match = (p[0] == s[0]);
p++;
}
if (match ^ not) {
while ((p[0] != '\0') && (p[0] != ']'))
p++;
if (p[0] == ']')
return fnmatch(p+1, s+1);
}
}
}
break;
case '*':
if (fnmatch(p, s+1))
return fnmatch(p+1, s);
return 0;
case '\0':
if (s[0] == '\0') {
return 0;
}
break;
default:
if ((p[0] == s[0]) || (p[0] == '?'))
return fnmatch(p+1, s+1);
break;
}
return 1;
}
More information about the klibc
mailing list