diff options
| author | gingerBill <bill@gingerbill.org> | 2020-10-13 14:40:13 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-10-13 14:40:13 +0100 |
| commit | fa33476438521fcc6ec886e43f64efb82e0c16dd (patch) | |
| tree | 27ad65889c3b1b29f0ffbca1980b92a692a11519 /core/path | |
| parent | 1b4bccbc9401b3b00735038906d7ad6c2e309e95 (diff) | |
Improve default temp allocator; Fix filepath.abs behaviour on Windows
Diffstat (limited to 'core/path')
| -rw-r--r-- | core/path/filepath/path.odin | 6 | ||||
| -rw-r--r-- | core/path/filepath/path_windows.odin | 18 |
2 files changed, 13 insertions, 11 deletions
diff --git a/core/path/filepath/path.odin b/core/path/filepath/path.odin index 283eb3a9e..2142a674c 100644 --- a/core/path/filepath/path.odin +++ b/core/path/filepath/path.odin @@ -124,7 +124,7 @@ clean :: proc(path: string, allocator := context.allocator) -> string { r, dot_dot := 0, 0; if rooted { - lazy_buffer_append(out, '/'); + lazy_buffer_append(out, SEPARATOR); r, dot_dot = 1, 1; } @@ -144,7 +144,7 @@ clean :: proc(path: string, allocator := context.allocator) -> string { } case !rooted: if out.w > 0 { - lazy_buffer_append(out, '/'); + lazy_buffer_append(out, SEPARATOR); } lazy_buffer_append(out, '.'); lazy_buffer_append(out, '.'); @@ -152,7 +152,7 @@ clean :: proc(path: string, allocator := context.allocator) -> string { } case: if rooted && out.w != 1 || !rooted && out.w != 0 { - lazy_buffer_append(out, '/'); + lazy_buffer_append(out, SEPARATOR); } for ; r < n && !is_separator(path[r]); r += 1 { lazy_buffer_append(out, path[r]); diff --git a/core/path/filepath/path_windows.odin b/core/path/filepath/path_windows.odin index 239ff70b1..fc93bdfa2 100644 --- a/core/path/filepath/path_windows.odin +++ b/core/path/filepath/path_windows.odin @@ -49,14 +49,16 @@ is_abs :: proc(path: string) -> bool { @(private) -full_path :: proc(name: string, allocator := context.allocator) -> (path: string, err: os.Errno) { +temp_full_path :: proc(name: string) -> (path: string, err: os.Errno) { + ta := context.temp_allocator; + name := name; if name == "" { name = "."; } - p := win32.utf8_to_utf16(name, context.temp_allocator); - defer delete(p); - buf := make([dynamic]u16, 100, allocator); + + p := win32.utf8_to_utf16(name, ta); + buf := make([dynamic]u16, 100, ta); for { n := win32.GetFullPathNameW(raw_data(p), u32(len(buf)), raw_data(buf), nil); if n == 0 { @@ -64,7 +66,7 @@ full_path :: proc(name: string, allocator := context.allocator) -> (path: string return "", os.Errno(win32.GetLastError()); } if n <= u32(len(buf)) { - return win32.utf16_to_utf8(buf[:n]), os.ERROR_NONE; + return win32.utf16_to_utf8(buf[:n], ta), os.ERROR_NONE; } resize(&buf, len(buf)*2); } @@ -74,13 +76,13 @@ full_path :: proc(name: string, allocator := context.allocator) -> (path: string - abs :: proc(path: string, allocator := context.allocator) -> (string, bool) { - full_path, err := full_path(path, context.temp_allocator); + full_path, err := temp_full_path(path); if err != 0 { return "", false; } - return clean(full_path, allocator), true; + p := clean(full_path, allocator); + return p, true; } split_list :: proc(path: string, allocator := context.allocator) -> []string { |