aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-08-04 14:57:25 +0100
committergingerBill <bill@gingerbill.org>2024-08-04 14:57:25 +0100
commit93fabf862891a6ac8915aed9094cecceaa3cc61b (patch)
tree7529e9afc750e8ab23df37621a30a3cea8d34b14
parentfc10b781af46a5ed1678d046160820de54885879 (diff)
Replace `err != 0` with `err != nil` where possible
-rw-r--r--core/image/general_os.odin2
-rw-r--r--core/mem/virtual/file.odin4
-rw-r--r--core/path/filepath/match.odin4
-rw-r--r--core/path/filepath/path_windows.odin2
-rw-r--r--core/path/filepath/walk.odin27
-rw-r--r--core/prof/spall/spall_linux.odin13
6 files changed, 18 insertions, 34 deletions
diff --git a/core/image/general_os.odin b/core/image/general_os.odin
index 144a3470f..e1fe440a4 100644
--- a/core/image/general_os.odin
+++ b/core/image/general_os.odin
@@ -27,7 +27,7 @@ which :: proc{
which_file :: proc(path: string) -> Which_File_Type {
f, err := os.open(path)
- if err != 0 {
+ if err != nil {
return .Unknown
}
header: [128]byte
diff --git a/core/mem/virtual/file.odin b/core/mem/virtual/file.odin
index 5d7180588..2f852b40c 100644
--- a/core/mem/virtual/file.odin
+++ b/core/mem/virtual/file.odin
@@ -24,7 +24,7 @@ map_file :: proc{
map_file_from_path :: proc(filename: string, flags: Map_File_Flags) -> (data: []byte, error: Map_File_Error) {
fd, err := os.open(filename, os.O_RDWR)
- if err != 0 {
+ if err != nil {
return nil, .Open_Failure
}
defer os.close(fd)
@@ -34,7 +34,7 @@ map_file_from_path :: proc(filename: string, flags: Map_File_Flags) -> (data: []
map_file_from_file_descriptor :: proc(fd: uintptr, flags: Map_File_Flags) -> (data: []byte, error: Map_File_Error) {
size, os_err := os.file_size(os.Handle(fd))
- if os_err != 0 {
+ if os_err != nil {
return nil, .Stat_Failure
}
if size < 0 {
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
}
diff --git a/core/prof/spall/spall_linux.odin b/core/prof/spall/spall_linux.odin
index 89a4225d3..b25d2b336 100644
--- a/core/prof/spall/spall_linux.odin
+++ b/core/prof/spall/spall_linux.odin
@@ -11,20 +11,11 @@ MAX_RW :: 0x7fffffff
@(no_instrumentation)
_write :: proc "contextless" (fd: os.Handle, data: []byte) -> (n: int, err: os.Error) #no_bounds_check /* bounds check would segfault instrumentation */ {
- if len(data) == 0 {
- return 0, nil
- }
-
for n < len(data) {
chunk := data[:min(len(data), MAX_RW)]
- written, errno := linux.write(linux.Fd(fd), chunk)
- if errno != nil {
- return n, os.Platform_Error(errno)
- }
- n += written
+ n += linux.write(linux.Fd(fd), chunk) or_return
}
-
- return n, nil
+ return
}
CLOCK_MONOTONIC_RAW :: 4 // NOTE(tetra): "RAW" means: Not adjusted by NTP.