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;
}
/**
* @note
*/
static char *
xy_parent_dir (const char *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;
last = strrchr (dir, '/');
if (!last)
{
/* current dir */
return ".";
}
*last = '\0';
if (xy_on_windows)
{
last = strrchr (dir, '\\');
if (!last)
{
/* current dir */
return ".";
}
*last = '\0';
}
return xy_str_gsub (dir, "/", "\\");
else
{
last = strrchr (dir, '/');
if (!last)
{
/* current dir */
return ".";
}
*last = '\0';
}
return dir;
return dir;
}
#endif