-#define _GNU_SOURCE
-#include "test.h"
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
+#include "test.h"
-static void t(char *p, char *b) {
- char *tmp = strdup(p);
- char *s = basename(tmp);
-
- if (strcmp(b,s) != 0)
- error("basename(\"%s\") returned \"%s\"; expected \"%s\"\n", p, s, b);
- free(tmp);
+#define T(path, want) \
+{ \
+ char tmp[1000]; \
+ char *got = basename(strcpy(tmp, path)); \
+ if (strcmp(want, got) != 0) \
+ error("basename(\"%s\") got \"%s\" want \"%s\"\n", path, got, want); \
}
-void test_basename() {
+int main()
+{
if (strcmp(".", basename(0)) != 0)
error("basename(0) returned \"%s\"; expected \".\"\n", basename(0));
- t("", ".");
- t("/usr/lib", "lib");
- t("/usr/", "usr");
- t("/", "/");
- t("///", "/");
- t("//usr//lib//", "lib");
+ T("", ".");
+ T("/usr/lib", "lib");
+ T("/usr/", "usr");
+ T("usr/", "usr");
+ T("/", "/");
+ T("///", "/");
+ T("//usr//lib//", "lib");
+ return test_status;
}