Merge pull request #6528 from Faker-09/filepath_dir_empty_path_fix

filepath.dir empty path fix
This commit is contained in:
Jeroen van Rijn
2026-04-07 18:02:54 +02:00
committed by GitHub

View File

@@ -245,12 +245,12 @@ rel :: proc(base_path, target_path: string, allocator := context.allocator) -> (
}
/*
Returns all but the last element path, usually the path's directory. Once the final element has been removed,
`dir` calls `clean` on the path and trailing separators are removed. If the path consists purely of separators,
then `"."` is returned.
Returns all but the last path element, usually the path's directory. Once the final element has been removed,
`dir` calls `clean` on the path and trailing separators are removed. If the path is empty or consists purely
of separators, then `"."` is returned.
*/
dir :: proc(path: string, allocator := context.allocator) -> string {
i := len(path) - 1
i := len(path) > 0 ? len(path) - 1 : 0
for i > 0 && !is_separator(path[i]) {
i -= 1
}