summaryrefslogtreecommitdiffstats
path: root/libc-top-half/musl/src/misc/dirname.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc-top-half/musl/src/misc/dirname.c')
-rw-r--r--libc-top-half/musl/src/misc/dirname.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/misc/dirname.c b/libc-top-half/musl/src/misc/dirname.c
new file mode 100644
index 0000000..dd57088
--- /dev/null
+++ b/libc-top-half/musl/src/misc/dirname.c
@@ -0,0 +1,14 @@
+#include <string.h>
+#include <libgen.h>
+
+char *dirname(char *s)
+{
+ size_t i;
+ if (!s || !*s) return ".";
+ i = strlen(s)-1;
+ for (; s[i]=='/'; i--) if (!i) return "/";
+ for (; s[i]!='/'; i--) if (!i) return ".";
+ for (; s[i]=='/'; i--) if (!i) return "/";
+ s[i+1] = 0;
+ return s;
+}