diff options
| author | gingerBill <bill@gingerbill.org> | 2024-08-04 14:57:25 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2024-08-04 14:57:25 +0100 |
| commit | 93fabf862891a6ac8915aed9094cecceaa3cc61b (patch) | |
| tree | 7529e9afc750e8ab23df37621a30a3cea8d34b14 /core/path/filepath | |
| parent | fc10b781af46a5ed1678d046160820de54885879 (diff) | |
Replace `err != 0` with `err != nil` where possible
Diffstat (limited to 'core/path/filepath')
| -rw-r--r-- | core/path/filepath/match.odin | 4 | ||||
| -rw-r--r-- | core/path/filepath/path_windows.odin | 2 | ||||
| -rw-r--r-- | core/path/filepath/walk.odin | 27 |
3 files changed, 13 insertions, 20 deletions
diff --git a/core/path/filepath/match.odin b/core/path/filepath/match.odin index 1279bdd84..7eb72b9a7 100644 --- a/core/path/filepath/match.odin +++ b/core/path/filepath/match.odin @@ -271,7 +271,7 @@ _glob :: proc(dir, pattern: string, matches: ^[dynamic]string, allocator := cont d, derr := os.open(dir, os.O_RDONLY) - if derr != 0 { + if derr != nil { return } defer os.close(d) @@ -280,7 +280,7 @@ _glob :: proc(dir, pattern: string, matches: ^[dynamic]string, allocator := cont file_info, ferr := os.fstat(d) defer os.file_info_delete(file_info) - if ferr != 0 { + if ferr != nil { return } if !file_info.is_dir { diff --git a/core/path/filepath/path_windows.odin b/core/path/filepath/path_windows.odin index d886d71da..0dcb28cf8 100644 --- a/core/path/filepath/path_windows.odin +++ b/core/path/filepath/path_windows.odin @@ -81,7 +81,7 @@ temp_full_path :: proc(name: string) -> (path: string, err: os.Error) { abs :: proc(path: string, allocator := context.allocator) -> (string, bool) { runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = allocator == context.temp_allocator) full_path, err := temp_full_path(path) - if err != 0 { + if err != nil { return "", false } p := clean(full_path, allocator) diff --git a/core/path/filepath/walk.odin b/core/path/filepath/walk.odin index 9fd4c455f..51dfa71d2 100644 --- a/core/path/filepath/walk.odin +++ b/core/path/filepath/walk.odin @@ -27,12 +27,12 @@ walk :: proc(root: string, walk_proc: Walk_Proc, user_data: rawptr) -> os.Error defer os.file_info_delete(info, context.temp_allocator) skip_dir: bool - if err != 0 { + if err != nil { err, skip_dir = walk_proc(info, err, user_data) } else { err, skip_dir = _walk(info, walk_proc, user_data) } - return 0 if skip_dir else err + return nil if skip_dir else err } @@ -43,7 +43,7 @@ _walk :: proc(info: os.File_Info, walk_proc: Walk_Proc, user_data: rawptr) -> (e // ignore empty things return } - return walk_proc(info, 0, user_data) + return walk_proc(info, nil, user_data) } fis: []os.File_Info @@ -52,14 +52,14 @@ _walk :: proc(info: os.File_Info, walk_proc: Walk_Proc, user_data: rawptr) -> (e defer os.file_info_slice_delete(fis, context.temp_allocator) err1, skip_dir = walk_proc(info, err, user_data) - if err != 0 || err1 != 0 || skip_dir { + if err != nil || err1 != nil || skip_dir { err = err1 return } for fi in fis { err, skip_dir = _walk(fi, walk_proc, user_data) - if err != 0 || skip_dir { + if err != nil || skip_dir { if !fi.is_dir || !skip_dir { return } @@ -70,19 +70,12 @@ _walk :: proc(info: os.File_Info, walk_proc: Walk_Proc, user_data: rawptr) -> (e } @(private) -read_dir :: proc(dir_name: string, allocator := context.temp_allocator) -> ([]os.File_Info, os.Error) { - f, err := os.open(dir_name, os.O_RDONLY) - if err != 0 { - return nil, err - } - fis: []os.File_Info - fis, err = os.read_dir(f, -1, allocator) - os.close(f) - if err != 0 { - return nil, err - } +read_dir :: proc(dir_name: string, allocator := context.temp_allocator) -> (fis: []os.File_Info, err: os.Error) { + f := os.open(dir_name, os.O_RDONLY) or_return + defer os.close(f) + fis = os.read_dir(f, -1, allocator) or_return slice.sort_by(fis, proc(a, b: os.File_Info) -> bool { return a.name < b.name }) - return fis, 0 + return } |