Fix typo; remove unneeded casts

This commit is contained in:
gingerBill
2024-08-04 12:39:21 +01:00
parent e8b6d15db9
commit bdbbbf5c95
6 changed files with 118 additions and 118 deletions
+23 -23
View File
@@ -421,7 +421,7 @@ W_OK :: 2 // Test for write permission
R_OK :: 4 // Test for read permission
foreign libc {
@(link_name="__error") __error_location :: proc() -> ^c.int ---
@(link_name="__errno") __errno_location :: proc() -> ^c.int ---
@(link_name="open") _unix_open :: proc(path: cstring, flags: c.int, mode: c.int) -> Handle ---
@(link_name="close") _unix_close :: proc(fd: Handle) -> c.int ---
@@ -480,7 +480,7 @@ is_path_separator :: proc(r: rune) -> bool {
@(require_results, no_instrumentation)
get_last_error :: proc "contextless" () -> Error {
return Platform_Error(__error_location()^)
return Platform_Error(__errno_location()^)
}
@(require_results)
@@ -489,7 +489,7 @@ open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0) -> (Handle, Err
cstr := strings.clone_to_cstring(path, context.temp_allocator)
handle := _unix_open(cstr, c.int(flags), c.int(mode))
if handle == -1 {
return INVALID_HANDLE, Error(get_last_error())
return INVALID_HANDLE, get_last_error()
}
return handle, nil
}
@@ -497,7 +497,7 @@ open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0) -> (Handle, Err
close :: proc(fd: Handle) -> Error {
result := _unix_close(fd)
if result == -1 {
return Error(get_last_error())
return get_last_error()
}
return nil
}
@@ -510,7 +510,7 @@ read :: proc(fd: Handle, data: []byte) -> (int, Error) {
to_read := min(c.size_t(len(data)), MAX_RW)
bytes_read := _unix_read(fd, &data[0], to_read)
if bytes_read == -1 {
return -1, Error(get_last_error())
return -1, get_last_error()
}
return int(bytes_read), nil
}
@@ -523,7 +523,7 @@ write :: proc(fd: Handle, data: []byte) -> (int, Error) {
to_write := min(c.size_t(len(data)), MAX_RW)
bytes_written := _unix_write(fd, &data[0], to_write)
if bytes_written == -1 {
return -1, Error(get_last_error())
return -1, get_last_error()
}
return int(bytes_written), nil
}
@@ -531,7 +531,7 @@ write :: proc(fd: Handle, data: []byte) -> (int, Error) {
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Error) {
res := _unix_seek(fd, offset, c.int(whence))
if res == -1 {
return -1, Error(get_last_error())
return -1, get_last_error()
}
return res, nil
}
@@ -549,7 +549,7 @@ rename :: proc(old_path, new_path: string) -> Error {
new_path_cstr := strings.clone_to_cstring(new_path, context.temp_allocator)
res := _unix_rename(old_path_cstr, new_path_cstr)
if res == -1 {
return Error(get_last_error())
return get_last_error()
}
return nil
}
@@ -559,7 +559,7 @@ remove :: proc(path: string) -> Error {
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
res := _unix_unlink(path_cstr)
if res == -1 {
return Error(get_last_error())
return get_last_error()
}
return nil
}
@@ -569,7 +569,7 @@ make_directory :: proc(path: string, mode: mode_t = 0o775) -> Error {
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
res := _unix_mkdir(path_cstr, mode)
if res == -1 {
return Error(get_last_error())
return get_last_error()
}
return nil
}
@@ -579,7 +579,7 @@ remove_directory :: proc(path: string) -> Error {
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
res := _unix_rmdir(path_cstr)
if res == -1 {
return Error(get_last_error())
return get_last_error()
}
return nil
}
@@ -641,7 +641,7 @@ exists :: proc(path: string) -> bool {
fcntl :: proc(fd: int, cmd: int, arg: int) -> (int, Error) {
result := _unix_fcntl(Handle(fd), c.int(cmd), uintptr(arg))
if result < 0 {
return 0, Error(get_last_error())
return 0, get_last_error()
}
return int(result), nil
}
@@ -671,7 +671,7 @@ _stat :: proc(path: string) -> (OS_Stat, Error) {
s: OS_Stat = ---
result := _unix_lstat(cstr, &s)
if result == -1 {
return s, Error(get_last_error())
return s, get_last_error()
}
return s, nil
}
@@ -685,7 +685,7 @@ _lstat :: proc(path: string) -> (OS_Stat, Error) {
s: OS_Stat = ---
res := _unix_lstat(cstr, &s)
if res == -1 {
return s, Error(get_last_error())
return s, get_last_error()
}
return s, nil
}
@@ -695,7 +695,7 @@ _fstat :: proc(fd: Handle) -> (OS_Stat, Error) {
s: OS_Stat = ---
result := _unix_fstat(fd, &s)
if result == -1 {
return s, Error(get_last_error())
return s, get_last_error()
}
return s, nil
}
@@ -704,7 +704,7 @@ _fstat :: proc(fd: Handle) -> (OS_Stat, Error) {
_fdopendir :: proc(fd: Handle) -> (Dir, Error) {
dirp := _unix_fdopendir(fd)
if dirp == cast(Dir)nil {
return nil, Error(get_last_error())
return nil, get_last_error()
}
return dirp, nil
}
@@ -713,7 +713,7 @@ _fdopendir :: proc(fd: Handle) -> (Dir, Error) {
_closedir :: proc(dirp: Dir) -> Error {
rc := _unix_closedir(dirp)
if rc != 0 {
return Error(get_last_error())
return get_last_error()
}
return nil
}
@@ -729,7 +729,7 @@ _readdir :: proc(dirp: Dir) -> (entry: Dirent, err: Error, end_of_stream: bool)
rc := _unix_readdir_r(dirp, &entry, &result)
if rc != 0 {
err = Error(get_last_error())
err = get_last_error()
return
}
err = nil
@@ -754,7 +754,7 @@ _readlink :: proc(path: string) -> (string, Error) {
rc := _unix_readlink(path_cstr, &(buf[0]), bufsz)
if rc == -1 {
delete(buf)
return "", Error(get_last_error())
return "", get_last_error()
} else if rc == int(bufsz) {
bufsz += MAX_PATH
delete(buf)
@@ -784,7 +784,7 @@ absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Error) {
path_ptr := _unix_realpath(rel_cstr, nil)
if path_ptr == nil {
return "", Error(get_last_error())
return "", get_last_error()
}
defer _unix_free(path_ptr)
@@ -799,7 +799,7 @@ access :: proc(path: string, mask: int) -> (bool, Error) {
cstr := strings.clone_to_cstring(path, context.temp_allocator)
result := _unix_access(cstr, c.int(mask))
if result == -1 {
return false, Error(get_last_error())
return false, get_last_error()
}
return true, nil
}
@@ -831,7 +831,7 @@ get_current_directory :: proc() -> string {
if cwd != nil {
return string(cwd)
}
if Error(get_last_error()) != ERANGE {
if get_last_error() != ERANGE {
delete(buf)
return ""
}
@@ -845,7 +845,7 @@ set_current_directory :: proc(path: string) -> (err: Error) {
cstr := strings.clone_to_cstring(path, context.temp_allocator)
res := _unix_chdir(cstr)
if res == -1 {
return Error(get_last_error())
return get_last_error()
}
return nil
}