2021-11-12 23:45:22 +01:00
|
|
|
#include <libgen.h>
|
2022-04-15 11:00:55 +02:00
|
|
|
#include <string.h>
|
2021-11-12 23:45:22 +01:00
|
|
|
|
2022-04-15 11:00:55 +02:00
|
|
|
char* basename(char* s)
|
2021-11-12 23:45:22 +01:00
|
|
|
{
|
|
|
|
size_t i;
|
2022-04-15 11:00:55 +02:00
|
|
|
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;
|
2021-11-12 23:45:22 +01:00
|
|
|
}
|