mirror of https://git.musl-libc.org/git/musl
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
14 lines
281 B
14 lines
281 B
#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;
|
|
}
|
|
|