Clean up err != nil usage

This commit is contained in:
gingerBill
2024-08-04 11:26:35 +01:00
parent 29b6eebcd5
commit a241168142
5 changed files with 21 additions and 33 deletions
+8 -7
View File
@@ -644,7 +644,7 @@ get_last_error_string :: proc() -> string {
}
open :: proc(path: string, flags: int = O_RDWR, mode: int = 0) -> (Handle, Errno) {
open :: proc(path: string, flags: int = O_RDWR, mode: int = 0) -> (handle: Handle, err: Errno) {
isDir := is_dir_path(path)
flags := flags
if isDir {
@@ -657,9 +657,10 @@ open :: proc(path: string, flags: int = O_RDWR, mode: int = 0) -> (Handle, Errno
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
cstr := strings.clone_to_cstring(path, context.temp_allocator)
handle := _unix_open(cstr, i32(flags), u16(mode))
if handle == -1 {
return INVALID_HANDLE, get_last_error()
handle = _unix_open(cstr, i32(flags), u16(mode))
if handle == INVALID_HANDLE {
err = get_last_error()
return
}
/*
@@ -667,14 +668,14 @@ open :: proc(path: string, flags: int = O_RDWR, mode: int = 0) -> (Handle, Errno
should not happen if the handle is a directory
*/
if mode != 0 && !isDir {
err := fchmod(handle, cast(u16)mode)
err = fchmod(handle, cast(u16)mode)
if err != nil {
_unix_close(handle)
return INVALID_HANDLE, err
handle = INVALID_HANDLE
}
}
return handle, nil
return
}
fchmod :: proc(fd: Handle, mode: u16) -> Errno {