mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-19 21:10:30 +00:00
Replace err != 0 with err != nil where possible
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user