File tree Expand file tree Collapse file tree 1 file changed +17
-18
lines changed
Expand file tree Collapse file tree 1 file changed +17
-18
lines changed Original file line number Diff line number Diff line change @@ -927,32 +927,31 @@ xy_normalize_path (const char *path)
927927 return new ;
928928}
929929
930+ /**
931+ * @note 总是返回不含末尾斜杠的父目录路径
932+ */
930933static char *
931934xy_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
You can’t perform that action at this time.
0 commit comments