Blame src/misc/basename.c
|
nsz |
7308b3 |
#include <stdlib.h>
|
|
nsz |
7308b3 |
#include <string.h>
|
|
nsz |
7308b3 |
#include <libgen.h>
|
|
nsz |
5cde4d |
#include "test.h"
|
|
nsz |
7308b3 |
|
|
nsz |
462b4f |
#define T(path, want) \
|
|
nsz |
462b4f |
{ \
|
|
nsz |
462b4f |
char tmp[1000]; \
|
|
nsz |
462b4f |
char *got = basename(strcpy(tmp, path)); \
|
|
nsz |
462b4f |
if (strcmp(want, got) != 0) \
|
|
nsz |
462b4f |
error("basename(\"%s\") got \"%s\" want \"%s\"\n", path, got, want); \
|
|
nsz |
7308b3 |
}
|
|
nsz |
7308b3 |
|
|
nsz |
462b4f |
int main()
|
|
nsz |
462b4f |
{
|
|
nsz |
7308b3 |
if (strcmp(".", basename(0)) != 0)
|
|
nsz |
7308b3 |
error("basename(0) returned \"%s\"; expected \".\"\n", basename(0));
|
|
nsz |
462b4f |
T("", ".");
|
|
nsz |
462b4f |
T("/usr/lib", "lib");
|
|
nsz |
462b4f |
T("/usr/", "usr");
|
|
nsz |
462b4f |
T("usr/", "usr");
|
|
nsz |
462b4f |
T("/", "/");
|
|
nsz |
462b4f |
T("///", "/");
|
|
nsz |
462b4f |
T("//usr//lib//", "lib");
|
|
nsz |
462b4f |
return test_status;
|
|
nsz |
7308b3 |
}
|