basename,dirname test fix (feature test macro)
[libc-test] / src / misc / dirname.c
1 #define _POSIX_C_SOURCE 200809L
2 #include <stdlib.h>
3 #include <string.h>
4 #include <libgen.h>
5 #include "test.h"
6
7 static void t(char *p, char *b) {
8         char *tmp = strdup(p);
9         char *s = dirname(tmp);
10
11         if (strcmp(b,s) != 0)
12                 error("dirname(\"%s\") returned \"%s\"; expected \"%s\"\n", p, s, b);
13         free(tmp);
14 }
15
16 void test_dirname() {
17         if (strcmp(dirname(0), ".") != 0)
18                 error("dirname(0) returned \"%s\"; expected \".\"\n", dirname(0));
19         t("", ".");
20         t("/usr/lib", "/usr");
21         t("/usr/", "/");
22         t("usr", ".");
23         t("/", "/");
24         t("///", "/");
25         t(".", ".");
26         t("..", ".");
27 }