From a9baddd7d07b9fe15e212985a808a79773ec72e4 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 19 Mar 2011 22:26:06 -0400 Subject: initial check-in, taken from old libc svn repo with significant additions --- dirname.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 dirname.c (limited to 'dirname.c') diff --git a/dirname.c b/dirname.c new file mode 100644 index 0000000..761512a --- /dev/null +++ b/dirname.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +#define TEST(p, b) ( \ +tmp = strdup((p)), s = dirname(tmp), \ +!strcmp((b),s) || \ +(printf(__FILE__ ":%d: dirname(\"%s\") returned \"%s\"; expected \"%s\"\n", \ +__LINE__, (p), s, (b)), err++, 0), free(tmp), 0 ) + +int test_dirname(void) +{ + char *tmp, *s; + int err=0; + + if (strcmp(dirname(NULL), ".")) { + printf(__FILE__ ":%d: dirname(NULL) returned \"%s\"; " + "expected \".\"\n", __LINE__, dirname(NULL)); + err++; + } + TEST("", "."); + TEST("/usr/lib", "/usr"); + TEST("/usr/", "/"); + TEST("usr", "."); + TEST("/", "/"); + TEST("///", "/"); + TEST(".", "."); + TEST("..", "."); + + return err; +} -- cgit v1.2.1