fix parent

This commit is contained in:
Mikachu2333 2025-08-17 19:52:04 +08:00 committed by 曾奥然
parent 0a91a9bdd5
commit 07685390b0

View File

@ -927,32 +927,31 @@ xy_normalize_path (const char *path)
return new; return new;
} }
/**
* @note
*/
static char * static char *
xy_parent_dir (const char *path) xy_parent_dir (const char *path)
{ {
char *dir = xy_normalize_path (path); char *dir = xy_normalize_path (path);
dir = xy_str_gsub (dir, "\\", "/");
if (xy_str_end_with (dir, "/"))
dir = xy_str_delete_suffix (dir, "/");
char *last = NULL; char *last = NULL;
last = strrchr (dir, '/');
if (!last)
{
/* current dir */
return ".";
}
*last = '\0';
if (xy_on_windows) if (xy_on_windows)
{ return xy_str_gsub (dir, "/", "\\");
last = strrchr (dir, '\\');
if (!last)
{
/* current dir */
return ".";
}
*last = '\0';
}
else else
{ return dir;
last = strrchr (dir, '/');
if (!last)
{
/* current dir */
return ".";
}
*last = '\0';
}
return dir;
} }
#endif #endif