projects
/
oweals
/
musl.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
yet another ugly legacy syscall rename...
[oweals/musl.git]
/
src
/
misc
/
dirname.c
1
#include <string.h>
2
#include <libgen.h>
3
4
char *dirname(char *s)
5
{
6
size_t i;
7
if (!s || !*s || !strchr(s, '/')) return ".";
8
i = strlen(s)-1;
9
for (; i&&s[i]=='/'; i--);
10
for (; i&&s[i-1]!='/'; i--);
11
for (; i&&s[i-1]=='/'; i--);
12
if (!i && *s=='/') i++;
13
s[i] = 0;
14
return s;
15
}