mirror of
https://github.com/fabiangreffrath/woof.git
synced 2025-09-23 03:52:12 -04:00
split dirname and basename at both types of slashes on Windows (#439)
User-supplied path names may still contain both types of slashes, i.e. forward and backward slashes. Fixes #437
This commit is contained in:
parent
9b138df643
commit
2eb9a183be
@ -189,15 +189,21 @@ boolean M_StrToInt(const char *str, int *result)
|
||||
|
||||
char *M_DirName(const char *path)
|
||||
{
|
||||
char *p, *result;
|
||||
char *pf, *pb, *result;
|
||||
|
||||
p = strrchr(path, DIR_SEPARATOR);
|
||||
if (p == NULL)
|
||||
pf = strrchr(path, '/');
|
||||
#ifdef _WIN32
|
||||
pb = strrchr(path, '\\');
|
||||
#else
|
||||
pb = NULL;
|
||||
#endif
|
||||
if (pf == NULL && pb == NULL)
|
||||
{
|
||||
return M_StringDuplicate(".");
|
||||
}
|
||||
else
|
||||
{
|
||||
char *p = MAX(pf, pb);
|
||||
result = M_StringDuplicate(path);
|
||||
result[p - path] = '\0';
|
||||
return result;
|
||||
@ -210,15 +216,21 @@ char *M_DirName(const char *path)
|
||||
|
||||
const char *M_BaseName(const char *path)
|
||||
{
|
||||
const char *p;
|
||||
const char *pf, *pb;
|
||||
|
||||
p = strrchr(path, DIR_SEPARATOR);
|
||||
if (p == NULL)
|
||||
pf = strrchr(path, '/');
|
||||
#ifdef _WIN32
|
||||
pb = strrchr(path, '\\');
|
||||
#else
|
||||
pb = NULL;
|
||||
#endif
|
||||
if (pf == NULL && pb == NULL)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *p = MAX(pf, pb);
|
||||
return p + 1;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user