• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 = basename(strcpy(tmp, path)); \
10 	if (strcmp(want, got) != 0) \
11 		t_error("basename(\"%s\") got \"%s\" want \"%s\"\n", path, got, want); \
12 }
13 
main()14 int main()
15 {
16 	if (strcmp(basename(0), ".") != 0)
17 		t_error("basename(0) returned \"%s\"; expected \".\"\n", basename(0));
18 	T("", ".");
19 	T("/usr/lib", "lib");
20 	T("/usr/", "usr");
21 	T("usr/", "usr");
22 	T("/", "/");
23 	T("///", "/");
24 	T("//usr//lib//", "lib");
25 	T(".", ".");
26 	T("..", "..");
27 	return t_status;
28 }
29