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* dirname(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 (; s[i] == '/'; i--)
|
|
|
|
if (!i)
|
|
|
|
return "/";
|
|
|
|
for (; s[i] != '/'; i--)
|
|
|
|
if (!i)
|
|
|
|
return ".";
|
|
|
|
for (; s[i] == '/'; i--)
|
|
|
|
if (!i)
|
|
|
|
return "/";
|
|
|
|
s[i + 1] = 0;
|
2021-11-12 23:45:22 +01:00
|
|
|
return s;
|
2022-04-15 11:00:55 +02:00
|
|
|
}
|