mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-18 11:52:22 -07:00
Clean up err != nil usage
This commit is contained in:
@@ -531,14 +531,9 @@ ftruncate :: proc(fd: Handle, length: i64) -> (err: Errno) {
|
||||
}
|
||||
|
||||
truncate :: proc(path: string, length: i64) -> (err: Errno) {
|
||||
fd: Handle
|
||||
fd, err = open(path, O_WRONLY|O_CREATE, 0o666)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fd := open(path, O_WRONLY|O_CREATE, 0o666) or_return
|
||||
defer close(fd)
|
||||
err = ftruncate(fd, length)
|
||||
return
|
||||
return ftruncate(fd, length)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -173,11 +173,8 @@ write_entire_file :: proc(name: string, data: []byte, perm: int, truncate := tru
|
||||
if truncate {
|
||||
flags |= O_TRUNC
|
||||
}
|
||||
f, err := open(name, flags, perm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = write(f, data)
|
||||
f := open(name, flags, perm) or_return
|
||||
_, err := write(f, data)
|
||||
if cerr := close(f); cerr != nil && err == nil {
|
||||
err = cerr
|
||||
}
|
||||
|
||||
@@ -6,25 +6,22 @@ import "core:time"
|
||||
import "core:strings"
|
||||
import win32 "core:sys/windows"
|
||||
|
||||
_fstat :: proc(f: ^File, allocator: runtime.Allocator) -> (File_Info, Error) {
|
||||
_fstat :: proc(f: ^File, allocator: runtime.Allocator) -> (fi: File_Info, err: Error) {
|
||||
if f == nil || (^File_Impl)(f.impl).fd == nil {
|
||||
return {}, nil
|
||||
return
|
||||
}
|
||||
|
||||
path, err := _cleanpath_from_handle(f, allocator)
|
||||
if err != nil {
|
||||
return {}, err
|
||||
}
|
||||
path := _cleanpath_from_handle(f, allocator) or_return
|
||||
|
||||
h := _handle(f)
|
||||
switch win32.GetFileType(h) {
|
||||
case win32.FILE_TYPE_PIPE, win32.FILE_TYPE_CHAR:
|
||||
fi := File_Info {
|
||||
fi = File_Info {
|
||||
fullpath = path,
|
||||
name = basename(path),
|
||||
type = file_type(h),
|
||||
}
|
||||
return fi, nil
|
||||
return
|
||||
}
|
||||
|
||||
return _file_info_from_get_file_information_by_handle(path, h, allocator)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -219,12 +219,10 @@ _processor_core_count :: proc() -> int {
|
||||
return 1
|
||||
}
|
||||
|
||||
file_size :: proc(fd: Handle) -> (i64, Errno) {
|
||||
stat, err := wasi.fd_filestat_get(wasi.fd_t(fd))
|
||||
if err != nil {
|
||||
return 0, Platform_Error(err)
|
||||
}
|
||||
return i64(stat.size), nil
|
||||
file_size :: proc(fd: Handle) -> (size: i64, err: Errno) {
|
||||
stat := wasi.fd_filestat_get(wasi.fd_t(fd)) or_return
|
||||
size = i64(stat.size)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user