diff options
| author | gingerBill <bill@gingerbill.org> | 2024-02-06 23:39:20 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2024-02-06 23:39:20 +0000 |
| commit | 4035a226dacc252508195db78bfc0148f2332084 (patch) | |
| tree | f829570c8c278e4f865fb452b06fbdc622bb0d3e /core/path | |
| parent | df5ee2dd06d0ac4abc130775e4d8fc43c35df814 (diff) | |
Fix filepath.rel allocation behaviour
Diffstat (limited to 'core/path')
| -rw-r--r-- | core/path/filepath/path.odin | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/core/path/filepath/path.odin b/core/path/filepath/path.odin index 21183e0f7..59a0f7f1c 100644 --- a/core/path/filepath/path.odin +++ b/core/path/filepath/path.odin @@ -356,28 +356,24 @@ Relative_Error :: enum { */ rel :: proc(base_path, target_path: string, allocator := context.allocator) -> (string, Relative_Error) { context.allocator = allocator - base_clean, target_clean := clean(base_path), clean(target_path) - - delete_target := true - defer { - if delete_target { - delete(target_clean) - } - delete(base_clean) - } + base_clean := clean(base_path, allocator) + target_clean := clean(target_path, allocator) + defer delete(base_clean, allocator) + defer delete(target_clean, allocator) if strings.equal_fold(target_clean, base_clean) { - return strings.clone("."), .None + return strings.clone(".", allocator), .None } - base_vol, target_vol := volume_name(base_path), volume_name(target_path) - base := base_clean[len(base_vol):] + base_vol := volume_name(base_path) + target_vol := volume_name(target_path) + base := base_clean [len(base_vol):] target := target_clean[len(target_vol):] if base == "." { base = "" } - base_slashed := len(base) > 0 && base[0] == SEPARATOR + base_slashed := len(base) > 0 && base [0] == SEPARATOR target_slashed := len(target) > 0 && target[0] == SEPARATOR if base_slashed != target_slashed || !strings.equal_fold(base_vol, target_vol) { return "", .Cannot_Relate @@ -413,7 +409,7 @@ rel :: proc(base_path, target_path: string, allocator := context.allocator) -> ( if tl != t0 { size += 1 + tl - t0 } - buf := make([]byte, size) + buf := make([]byte, size, allocator) n := copy(buf, "..") for _ in 0..<seps { buf[n] = SEPARATOR @@ -427,8 +423,7 @@ rel :: proc(base_path, target_path: string, allocator := context.allocator) -> ( return string(buf), .None } - delete_target = false - return target[t0:], .None + return strings.clone(target[t0:], allocator), .None } /* |