Skip to content

Commit 0768539

Browse files
Mikachu2333ccmywish
authored andcommitted
fix parent
1 parent 0a91a9b commit 0768539

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

lib/xy.h

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -927,32 +927,31 @@ xy_normalize_path (const char *path)
927927
return new;
928928
}
929929

930+
/**
931+
* @note 总是返回不含末尾斜杠的父目录路径
932+
*/
930933
static char *
931934
xy_parent_dir (const char *path)
932935
{
933936
char *dir = xy_normalize_path (path);
937+
dir = xy_str_gsub (dir, "\\", "/");
938+
if (xy_str_end_with (dir, "/"))
939+
dir = xy_str_delete_suffix (dir, "/");
940+
934941
char *last = NULL;
935-
if (xy_on_windows)
942+
943+
last = strrchr (dir, '/');
944+
if (!last)
936945
{
937-
last = strrchr (dir, '\\');
938-
if (!last)
939-
{
940-
/* current dir */
941-
return ".";
942-
}
943-
*last = '\0';
946+
/* current dir */
947+
return ".";
944948
}
949+
*last = '\0';
950+
951+
if (xy_on_windows)
952+
return xy_str_gsub (dir, "/", "\\");
945953
else
946-
{
947-
last = strrchr (dir, '/');
948-
if (!last)
949-
{
950-
/* current dir */
951-
return ".";
952-
}
953-
*last = '\0';
954-
}
955-
return dir;
954+
return dir;
956955
}
957956

958957
#endif

0 commit comments

Comments
 (0)