1#include <stdlib.h>
2#include <string.h>
3#include <libgen.h>
4#include "test.h"
5
6#define T(path, want) \
7{ \
8	char tmp[100]; \
9	char *got = dirname(strcpy(tmp, path)); \
10	if (strcmp(want, got) != 0) \
11		t_error("dirname(\"%s\") got \"%s\" want \"%s\"\n", path, got, want); \
12}
13
14int main()
15{
16	if (strcmp(dirname(0), ".") != 0)
17		t_error("dirname(0) returned \"%s\"; expected \".\"\n", dirname(0));
18	T("", ".");
19	T("/usr/lib", "/usr");
20	T("/usr/", "/");
21	T("usr", ".");
22	T("usr/", ".");
23	T("/", "/");
24	T("///", "/");
25	T(".", ".");
26	T("..", ".");
27	return t_status;
28}
29