kolibrios/programs/develop/ktcc/trunk/libc.obj/source/misc/dirname.c
turbocat 9257d2c34c libc.obj:
- Added basename() and  dirname()
 - libc_test all tabs -> spaces

git-svn-id: svn://kolibrios.org@9262 a494cfbc-eb01-0410-851d-a64ba20cac60
2021-11-12 22:45:22 +00:00

15 lines
306 B
C

#include <string.h>
#include <libgen.h>
char *dirname(char *s)
{
size_t i;
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;
return s;
}