summaryrefslogtreecommitdiff
path: root/dirname.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-03-19 22:26:06 -0400
committerRich Felker <dalias@aerifal.cx>2011-03-19 22:26:06 -0400
commita9baddd7d07b9fe15e212985a808a79773ec72e4 (patch)
treefce0a089eedeacef8b25b409c2ba50f5f30a8327 /dirname.c
downloadlibc-testsuite-a9baddd7d07b9fe15e212985a808a79773ec72e4.tar.gz
initial check-in, taken from old libc svn repo with significant additions
Diffstat (limited to 'dirname.c')
-rw-r--r--dirname.c32
1 files changed, 32 insertions, 0 deletions
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 <stdio.h>
+#include <string.h>
+#include <libgen.h>
+#include <stdlib.h>
+
+#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;
+}