mirror of
https://github.com/fluencelabs/musl
synced 2025-06-13 23:11:51 +00:00
note that regardless of the name used, basename is always conformant. it never takes on the bogus gnu behavior, unlike glibc where basename is nonconformant when declared manually without including libgen.h.
16 lines
263 B
C
16 lines
263 B
C
#include <string.h>
|
|
#include <libgen.h>
|
|
#include "libc.h"
|
|
|
|
char *basename(char *s)
|
|
{
|
|
size_t i;
|
|
if (!s || !*s) return ".";
|
|
i = strlen(s)-1;
|
|
for (; i&&s[i]=='/'; i--) s[i] = 0;
|
|
for (; i&&s[i-1]!='/'; i--);
|
|
return s+i;
|
|
}
|
|
|
|
weak_alias(basename, __xpg_basename);
|