diff options
| author | Luka Aleksić <laleksic@mail.ru> | 2021-01-21 20:20:38 +0100 |
|---|---|---|
| committer | Luka Aleksić <laleksic@mail.ru> | 2021-01-21 20:20:38 +0100 |
| commit | 92e23ec3979623418ce8eb2d2faafee2de3c5a2c (patch) | |
| tree | 83c477e9607c2946457c55ba09cdcd41e849e473 /core/path | |
| parent | 00ebc877a17bebd2215fcdbf2b9a5dc9aeed4ee5 (diff) | |
* Add some procedures to path_unix to mirror the path_windows API
* Add files stat_linux and dir_linux to mirror the stat/dir_windows API
* Add helper functions to os_linux that are used by the above
Diffstat (limited to 'core/path')
| -rw-r--r-- | core/path/filepath/match.odin | 18 | ||||
| -rw-r--r-- | core/path/filepath/path_unix.odin | 20 |
2 files changed, 30 insertions, 8 deletions
diff --git a/core/path/filepath/match.odin b/core/path/filepath/match.odin index 57307934e..1446ceb4d 100644 --- a/core/path/filepath/match.odin +++ b/core/path/filepath/match.odin @@ -218,6 +218,7 @@ get_escape :: proc(chunk: string) -> (r: rune, next_chunk: string, err: Match_Er // // glob ignores file system errors // + glob :: proc(pattern: string, allocator := context.allocator) -> (matches: []string, err: Match_Error) { if !has_meta(pattern) { // TODO(bill): os.lstat on here to check for error @@ -272,14 +273,15 @@ _glob :: proc(dir, pattern: string, matches: ^[dynamic]string) -> (m: [dynamic]s } defer os.close(d); - file_info, ferr := os.fstat(d); - if ferr != 0 { - os.file_info_delete(file_info); - return; - } - if !file_info.is_dir { - os.file_info_delete(file_info); - return; + { + file_info, ferr := os.fstat(d); + defer os.file_info_delete(file_info); + if ferr != 0 { + return; + } + if !file_info.is_dir { + return; + } } diff --git a/core/path/filepath/path_unix.odin b/core/path/filepath/path_unix.odin index c9d0e28f1..faf1d9568 100644 --- a/core/path/filepath/path_unix.odin +++ b/core/path/filepath/path_unix.odin @@ -1,6 +1,26 @@ //+build linux, darwin, freebsd package filepath +import "core:strings" +import "core:os" + SEPARATOR :: '/'; SEPARATOR_STRING :: `/`; LIST_SEPARATOR :: ':'; + +abs :: proc(path: string, allocator := context.allocator) -> (string, bool) { + full_path, err := os.absolute_path_from_relative(path); + if err != os.ERROR_NONE { + return "", false; + } + return full_path, true; +} + +join :: proc(elems: ..string, allocator := context.allocator) -> string { + s := strings.join(elems, SEPARATOR_STRING); + return s; +} + +is_abs :: proc(path: string) -> bool { + return (path[0] == '/'); +} |