aboutsummaryrefslogtreecommitdiff
path: root/core/path
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2026-02-14 13:03:10 +0100
committerGitHub <noreply@github.com>2026-02-14 13:03:10 +0100
commitbea892bfe7e9279c4a9032df2015bc985b4569c2 (patch)
treef06c5a97b87e5c600d18075b6d498713f603aba6 /core/path
parent67922a57e90c78992cbe85e10003bc5c05bc0453 (diff)
parent1af1beb248fe8796023f77c1a4b4a326e772ea5c (diff)
Merge pull request #6274 from Kelimion/fp_dir
Fix `filepath.dir`
Diffstat (limited to 'core/path')
-rw-r--r--core/path/filepath/path.odin20
1 files changed, 4 insertions, 16 deletions
diff --git a/core/path/filepath/path.odin b/core/path/filepath/path.odin
index a325ce4cd..e383e756c 100644
--- a/core/path/filepath/path.odin
+++ b/core/path/filepath/path.odin
@@ -250,26 +250,14 @@ rel :: proc(base_path, target_path: string, allocator := context.allocator) -> (
then `"."` is returned.
*/
dir :: proc(path: string, allocator := context.allocator) -> string {
- context.allocator = allocator
- vol_len := len(volume_name(path))
- when ODIN_OS == .Windows {
- if len(path) >= 3 && is_separator(path[2]) {
- vol_len += 1
- }
- }
- vol := path[:vol_len]
-
i := len(path) - 1
- for i >= vol_len && !is_separator(path[i]) {
+ for i > 0 && !is_separator(path[i]) {
i -= 1
}
- dir, dir_err := clean(path[vol_len : i+1], allocator)
+ res, dir_err := clean(path[:i], allocator)
+
if dir_err != nil { return "" }
- defer delete(dir)
- if dir == "." && vol_len > 2 {
- return strings.clone(vol)
- }
- return strings.concatenate({vol, dir})
+ return res
}