Blame src/misc/dirname.c

nsz 7308b3
#define _GNU_SOURCE
nsz 7308b3
#include "test.h"
nsz 7308b3
#include <stdlib.h>
nsz 7308b3
#include <string.h>
nsz 7308b3
#include <libgen.h>
nsz 7308b3
nsz 7308b3
static void t(char *p, char *b) {
nsz 7308b3
	char *tmp = strdup(p);
nsz 7308b3
	char *s = dirname(tmp);
nsz 7308b3
nsz 7308b3
	if (strcmp(b,s) != 0)
nsz 7308b3
		error("dirname(\"%s\") returned \"%s\"; expected \"%s\"\n", p, s, b);
nsz 7308b3
	free(tmp);
nsz 7308b3
}
nsz 7308b3
nsz 7308b3
void test_dirname() {
nsz 7308b3
	if (strcmp(dirname(0), ".") != 0)
nsz 7308b3
		error("dirname(0) returned \"%s\"; expected \".\"\n", dirname(0));
nsz 7308b3
	t("", ".");
nsz 7308b3
	t("/usr/lib", "/usr");
nsz 7308b3
	t("/usr/", "/");
nsz 7308b3
	t("usr", ".");
nsz 7308b3
	t("/", "/");
nsz 7308b3
	t("///", "/");
nsz 7308b3
	t(".", ".");
nsz 7308b3
	t("..", ".");
nsz 7308b3
}