mirror of
https://github.com/fluencelabs/musl
synced 2025-06-27 05:32:06 +00:00
fix dirname to handle input of form "foo/" correctly
also optimized a bit.
This commit is contained in:
@ -4,12 +4,11 @@
|
||||
char *dirname(char *s)
|
||||
{
|
||||
size_t i;
|
||||
if (!s || !*s || !strchr(s, '/')) return ".";
|
||||
if (!s || !*s) return ".";
|
||||
i = strlen(s)-1;
|
||||
for (; i&&s[i]=='/'; i--);
|
||||
for (; i&&s[i-1]!='/'; i--);
|
||||
for (; i&&s[i-1]=='/'; i--);
|
||||
if (!i && *s=='/') i++;
|
||||
s[i] = 0;
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user