mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-30 06:21:07 +00:00
45a89cc6c6
1999-04-26 Ulrich Drepper <drepper@cygnus.com> * posix/fnmatch.c: Include string.h also for glibc. (fnmatch, case '?'): Optimize if cascades a bit. (fnmatch, case '*'): Correct handling if FNM_PATHNAME is set. * posix/testfnm.c: Add test cases for * with FNM_PATHNAME errors.
43 lines
913 B
C
43 lines
913 B
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include "fnmatch.h"
|
|
|
|
struct {
|
|
const char *name;
|
|
const char *pattern;
|
|
int flags;
|
|
int expected;
|
|
} tests[] = {
|
|
{ "lib", "*LIB*", FNM_PERIOD, FNM_NOMATCH },
|
|
{ "lib", "*LIB*", FNM_CASEFOLD|FNM_PERIOD, 0 },
|
|
{ "a/b", "a[/]b", 0, 0 },
|
|
{ "a/b", "a[/]b", FNM_PATHNAME, FNM_NOMATCH },
|
|
{ "a/b", "[a-z]/[a-z]", 0, 0 },
|
|
{ "a/b", "*", FNM_FILE_NAME, FNM_NOMATCH },
|
|
{ "a/b", "*[/]b", FNM_FILE_NAME, FNM_NOMATCH },
|
|
{ "a/b", "*[b]", FNM_FILE_NAME, FNM_NOMATCH }
|
|
};
|
|
|
|
int
|
|
main (void)
|
|
{
|
|
size_t i;
|
|
int errors = 0;
|
|
|
|
for (i = 0; i < sizeof (tests) / sizeof (*tests); i++)
|
|
{
|
|
int match;
|
|
|
|
match = fnmatch (tests[i].pattern, tests[i].name, tests[i].flags);
|
|
if (match != tests[i].expected)
|
|
{
|
|
printf ("%s %s %s\n", tests[i].pattern,
|
|
match == 0 ? "matches" : "does not match",
|
|
tests[i].name);
|
|
errors++;
|
|
}
|
|
}
|
|
|
|
exit (errors != 0);
|
|
}
|