X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fregex%2Ffnmatch.c;h=33f508ff6b9ec980a379a6df7712c61a868c94ab;hb=462b4f35652098e26c677f89df6990428a4aad6a;hp=c59c4b23543b8efd3f062e4bae195e88eb17933d;hpb=80371a77c4d6978e786ab2322161c4f8e299e891;p=libc-test diff --git a/src/regex/fnmatch.c b/src/regex/fnmatch.c index c59c4b2..33f508f 100644 --- a/src/regex/fnmatch.c +++ b/src/regex/fnmatch.c @@ -19,22 +19,26 @@ struct xlat { {0, NULL}, }; -static void printflags(const struct xlat *map, int flags) { +static char *flagstr(const struct xlat *map, int flags) +{ + static char buf[1000]; char *sep; if (!flags) { - fprintf(stderr, "0"); - return; + sprintf(buf, "0"); + return buf; } sep = ""; for (; map->str; map++) { if (map->val && (flags & map->val) == map->val) { - fprintf(stderr, "%s%s", sep, map->str); + sprintf(buf, "%s%s", sep, map->str); sep = "|"; flags &= ~(map->val); } } - if (flags) fprintf(stderr, "%sunknown=%#x", sep, flags); + if (flags) + sprintf(buf, "%sunknown=%#x", sep, flags); + return buf; } /* tests harness adapted from glibc testfnm.c */ @@ -114,7 +118,8 @@ struct { { "a[.]b", "a.b", FNM_PATHNAME|FNM_PERIOD, 0 }, }; -void test_fnmatch(void) { +int main(void) +{ int i; for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) { @@ -123,11 +128,11 @@ void test_fnmatch(void) { r = fnmatch(tests[i].pattern, tests[i].string, tests[i].flags); x = tests[i].expected; if (r != x && (r != FNM_NOMATCH || x != -FNM_NOMATCH)) { - error("fail - fnmatch(\"%s\", \"%s\", ", - tests[i].pattern, tests[i].string); - printflags(fnmatch_flags, tests[i].flags); - fprintf(stderr, ") => %d (expected %d)\n", - r, tests[i].expected); + error("fnmatch(\"%s\", \"%s\", %s) failed, got %d want %d\n", + tests[i].pattern, tests[i].string, + flagstr(fnmatch_flags, tests[i].flags), + r, x); } } + return test_status; }