mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-25 15:05:00 -07:00
More clean ups of ERROR_NONE and != nil usage
This commit is contained in:
+7
-17
@@ -4,20 +4,10 @@ package os
|
||||
import "core:strings"
|
||||
|
||||
read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []File_Info, err: Errno) {
|
||||
dirp: Dir
|
||||
dirp, err = _fdopendir(fd)
|
||||
if err != ERROR_NONE {
|
||||
return
|
||||
}
|
||||
|
||||
dirp := _fdopendir(fd) or_return
|
||||
defer _closedir(dirp)
|
||||
|
||||
dirpath: string
|
||||
dirpath, err = absolute_path_from_handle(fd)
|
||||
if err != ERROR_NONE {
|
||||
return
|
||||
}
|
||||
|
||||
dirpath := absolute_path_from_handle(fd) or_return
|
||||
defer delete(dirpath)
|
||||
|
||||
n := n
|
||||
@@ -27,8 +17,8 @@ read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []F
|
||||
size = 100
|
||||
}
|
||||
|
||||
dfi := make([dynamic]File_Info, 0, size, allocator)
|
||||
defer if err != ERROR_NONE {
|
||||
dfi := make([dynamic]File_Info, 0, size, allocator) or_return
|
||||
defer if err != nil {
|
||||
for fi_ in dfi {
|
||||
file_info_delete(fi_, allocator)
|
||||
}
|
||||
@@ -39,7 +29,7 @@ read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []F
|
||||
entry: Dirent
|
||||
end_of_stream: bool
|
||||
entry, err, end_of_stream = _readdir(dirp)
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return
|
||||
} else if end_of_stream {
|
||||
break
|
||||
@@ -56,7 +46,7 @@ read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []F
|
||||
|
||||
s: OS_Stat
|
||||
s, err = _lstat(fullpath)
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
delete(fullpath, allocator)
|
||||
return
|
||||
}
|
||||
@@ -67,5 +57,5 @@ read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []F
|
||||
append(&dfi, fi_)
|
||||
}
|
||||
|
||||
return dfi[:], ERROR_NONE
|
||||
return dfi[:], nil
|
||||
}
|
||||
|
||||
@@ -68,15 +68,14 @@ read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []F
|
||||
}
|
||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == allocator)
|
||||
|
||||
wpath: []u16
|
||||
wpath, err = cleanpath_from_handle_u16(fd, context.temp_allocator)
|
||||
if len(wpath) == 0 || err != ERROR_NONE {
|
||||
wpath := cleanpath_from_handle_u16(fd, context.temp_allocator) or_return
|
||||
if len(wpath) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
dfi := make([dynamic]File_Info, 0, size)
|
||||
dfi := make([dynamic]File_Info, 0, size) or_return
|
||||
|
||||
wpath_search := make([]u16, len(wpath)+3, context.temp_allocator)
|
||||
wpath_search := make([]u16, len(wpath)+3, context.temp_allocator) or_return
|
||||
copy(wpath_search, wpath)
|
||||
wpath_search[len(wpath)+0] = '\\'
|
||||
wpath_search[len(wpath)+1] = '*'
|
||||
@@ -109,5 +108,5 @@ read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []F
|
||||
}
|
||||
}
|
||||
|
||||
return dfi[:], ERROR_NONE
|
||||
return dfi[:], nil
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ lookup_env :: proc(key: string, allocator := context.allocator) -> (value: strin
|
||||
}
|
||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == allocator)
|
||||
|
||||
b := make([dynamic]u16, n, context.temp_allocator)
|
||||
b, _ := make([dynamic]u16, n, context.temp_allocator)
|
||||
n = win32.GetEnvironmentVariableW(wkey, raw_data(b), u32(len(b)))
|
||||
if n == 0 && get_last_error() == ERROR_ENVVAR_NOT_FOUND {
|
||||
return "", false
|
||||
@@ -61,13 +61,16 @@ unset_env :: proc(key: string) -> Errno {
|
||||
// environ returns a copy of strings representing the environment, in the form "key=value"
|
||||
// NOTE: the slice of strings and the strings with be allocated using the supplied allocator
|
||||
environ :: proc(allocator := context.allocator) -> []string {
|
||||
envs := cast([^]win32.WCHAR)(win32.GetEnvironmentStringsW())
|
||||
envs := ([^]win32.WCHAR)(win32.GetEnvironmentStringsW())
|
||||
if envs == nil {
|
||||
return nil
|
||||
}
|
||||
defer win32.FreeEnvironmentStringsW(envs)
|
||||
|
||||
r := make([dynamic]string, 0, 50, allocator)
|
||||
r, err := make([dynamic]string, 0, 50, allocator)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
for from, i := 0, 0; true; i += 1 {
|
||||
if c := envs[i]; c == 0 {
|
||||
if i <= from {
|
||||
|
||||
@@ -52,7 +52,7 @@ open :: proc(path: string, mode: int = O_RDONLY, perm: int = 0) -> (Handle, Errn
|
||||
wide_path := win32.utf8_to_wstring(path)
|
||||
handle := Handle(win32.CreateFileW(wide_path, access, share_mode, sa, create_mode, win32.FILE_ATTRIBUTE_NORMAL|win32.FILE_FLAG_BACKUP_SEMANTICS, nil))
|
||||
if handle != INVALID_HANDLE {
|
||||
return handle, ERROR_NONE
|
||||
return handle, nil
|
||||
}
|
||||
|
||||
err := get_last_error()
|
||||
@@ -77,7 +77,7 @@ flush :: proc(fd: Handle) -> (err: Errno) {
|
||||
|
||||
write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
single_write_length: win32.DWORD
|
||||
@@ -94,7 +94,7 @@ write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
}
|
||||
total_write += i64(single_write_length)
|
||||
}
|
||||
return int(total_write), ERROR_NONE
|
||||
return int(total_write), nil
|
||||
}
|
||||
|
||||
@(private="file")
|
||||
@@ -150,7 +150,7 @@ read_console :: proc(handle: win32.HANDLE, b: []byte) -> (n: int, err: Errno) {
|
||||
|
||||
read :: proc(fd: Handle, data: []byte) -> (total_read: int, err: Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
handle := win32.HANDLE(fd)
|
||||
@@ -176,7 +176,7 @@ read :: proc(fd: Handle, data: []byte) -> (total_read: int, err: Errno) {
|
||||
if bytes_read == 0 {
|
||||
return 0, ERROR_HANDLE_EOF
|
||||
} else {
|
||||
return int(bytes_read), ERROR_NONE
|
||||
return int(bytes_read), nil
|
||||
}
|
||||
} else {
|
||||
return 0, get_last_error()
|
||||
@@ -204,7 +204,7 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||
err := get_last_error()
|
||||
return 0, err
|
||||
}
|
||||
return i64(hi)<<32 + i64(dw_ptr), ERROR_NONE
|
||||
return i64(hi)<<32 + i64(dw_ptr), nil
|
||||
}
|
||||
|
||||
file_size :: proc(fd: Handle) -> (i64, Errno) {
|
||||
@@ -377,7 +377,7 @@ get_current_directory :: proc(allocator := context.allocator) -> string {
|
||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == allocator)
|
||||
|
||||
sz_utf16 := win32.GetCurrentDirectoryW(0, nil)
|
||||
dir_buf_wstr := make([]u16, sz_utf16, context.temp_allocator) // the first time, it _includes_ the NUL.
|
||||
dir_buf_wstr, _ := make([]u16, sz_utf16, context.temp_allocator) // the first time, it _includes_ the NUL.
|
||||
|
||||
sz_utf16 = win32.GetCurrentDirectoryW(win32.DWORD(len(dir_buf_wstr)), raw_data(dir_buf_wstr))
|
||||
assert(int(sz_utf16)+1 == len(dir_buf_wstr)) // the second time, it _excludes_ the NUL.
|
||||
@@ -458,7 +458,7 @@ fix_long_path :: proc(path: string) -> string {
|
||||
|
||||
prefix :: `\\?`
|
||||
|
||||
path_buf := make([]byte, len(prefix)+len(path)+len(`\`), context.temp_allocator)
|
||||
path_buf, _ := make([]byte, len(prefix)+len(path)+len(`\`), context.temp_allocator)
|
||||
copy(path_buf, prefix)
|
||||
n := len(path)
|
||||
r, w := 0, len(prefix)
|
||||
|
||||
+3
-3
@@ -145,13 +145,13 @@ read_entire_file_from_handle :: proc(fd: Handle, allocator := context.allocator,
|
||||
return nil, true
|
||||
}
|
||||
|
||||
data = make([]byte, int(length), allocator, loc)
|
||||
if data == nil {
|
||||
data, err = make([]byte, int(length), allocator, loc)
|
||||
if data == nil || err != nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
bytes_read, read_err := read_full(fd, data)
|
||||
if read_err != ERROR_NONE {
|
||||
if read_err != nil {
|
||||
delete(data)
|
||||
return nil, false
|
||||
}
|
||||
|
||||
+34
-46
@@ -698,7 +698,7 @@ MAX_RW :: 1 << 30
|
||||
|
||||
write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
to_write := min(c.size_t(len(data)), MAX_RW)
|
||||
@@ -707,12 +707,12 @@ write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if bytes_written < 0 {
|
||||
return -1, Errno(get_last_error())
|
||||
}
|
||||
return bytes_written, ERROR_NONE
|
||||
return bytes_written, nil
|
||||
}
|
||||
|
||||
read :: proc(fd: Handle, data: []u8) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
to_read := min(c.size_t(len(data)), MAX_RW)
|
||||
@@ -721,12 +721,12 @@ read :: proc(fd: Handle, data: []u8) -> (int, Errno) {
|
||||
if bytes_read < 0 {
|
||||
return -1, Errno(get_last_error())
|
||||
}
|
||||
return bytes_read, ERROR_NONE
|
||||
return bytes_read, nil
|
||||
}
|
||||
|
||||
read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
to_read := min(c.size_t(len(data)), MAX_RW)
|
||||
@@ -735,12 +735,12 @@ read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
||||
if bytes_read < 0 {
|
||||
return -1, Errno(get_last_error())
|
||||
}
|
||||
return bytes_read, ERROR_NONE
|
||||
return bytes_read, nil
|
||||
}
|
||||
|
||||
write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
to_write := min(c.size_t(len(data)), MAX_RW)
|
||||
@@ -749,7 +749,7 @@ write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
||||
if bytes_written < 0 {
|
||||
return -1, Errno(get_last_error())
|
||||
}
|
||||
return bytes_written, ERROR_NONE
|
||||
return bytes_written, nil
|
||||
}
|
||||
|
||||
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||
@@ -776,22 +776,16 @@ stdin: Handle = 0 // get_std_handle(win32.STD_INPUT_HANDLE);
|
||||
stdout: Handle = 1 // get_std_handle(win32.STD_OUTPUT_HANDLE);
|
||||
stderr: Handle = 2 // get_std_handle(win32.STD_ERROR_HANDLE);
|
||||
|
||||
last_write_time :: proc(fd: Handle) -> (File_Time, Errno) {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
return 0, err
|
||||
}
|
||||
last_write_time :: proc(fd: Handle) -> (time: File_Time, err: Errno) {
|
||||
s := _fstat(fd) or_return
|
||||
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
||||
return File_Time(modified), ERROR_NONE
|
||||
return File_Time(modified), nil
|
||||
}
|
||||
|
||||
last_write_time_by_name :: proc(name: string) -> (File_Time, Errno) {
|
||||
s, err := _stat(name)
|
||||
if err != ERROR_NONE {
|
||||
return 0, err
|
||||
}
|
||||
last_write_time_by_name :: proc(name: string) -> (time: File_Time, err: Errno) {
|
||||
s := _stat(name) or_return
|
||||
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
||||
return File_Time(modified), ERROR_NONE
|
||||
return File_Time(modified), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -801,7 +795,7 @@ is_path_separator :: proc(r: rune) -> bool {
|
||||
|
||||
is_file_handle :: proc(fd: Handle) -> bool {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISREG(s.mode)
|
||||
@@ -815,7 +809,7 @@ is_file_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||
} else {
|
||||
s, err = _lstat(path)
|
||||
}
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISREG(s.mode)
|
||||
@@ -824,7 +818,7 @@ is_file_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||
|
||||
is_dir_handle :: proc(fd: Handle) -> bool {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISDIR(s.mode)
|
||||
@@ -838,7 +832,7 @@ is_dir_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||
} else {
|
||||
s, err = _lstat(path)
|
||||
}
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISDIR(s.mode)
|
||||
@@ -881,7 +875,7 @@ _stat :: proc(path: string) -> (OS_Stat, Errno) {
|
||||
if result == -1 {
|
||||
return s, Errno(get_last_error())
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -894,7 +888,7 @@ _lstat :: proc(path: string) -> (OS_Stat, Errno) {
|
||||
if result == -1 {
|
||||
return s, Errno(get_last_error())
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -904,7 +898,7 @@ _fstat :: proc(fd: Handle) -> (OS_Stat, Errno) {
|
||||
if result == -1 {
|
||||
return s, Errno(get_last_error())
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -913,7 +907,7 @@ _fdopendir :: proc(fd: Handle) -> (Dir, Errno) {
|
||||
if dirp == cast(Dir)nil {
|
||||
return nil, Errno(get_last_error())
|
||||
}
|
||||
return dirp, ERROR_NONE
|
||||
return dirp, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -939,7 +933,6 @@ _readdir :: proc(dirp: Dir) -> (entry: Dirent, err: Errno, end_of_stream: bool)
|
||||
err = Errno(get_last_error())
|
||||
return
|
||||
}
|
||||
err = ERROR_NONE
|
||||
|
||||
if result == nil {
|
||||
end_of_stream = true
|
||||
@@ -968,20 +961,15 @@ _readlink :: proc(path: string) -> (string, Errno) {
|
||||
delete(buf)
|
||||
buf = make([]byte, bufsz)
|
||||
} else {
|
||||
return strings.string_from_ptr(&buf[0], rc), ERROR_NONE
|
||||
return strings.string_from_ptr(&buf[0], rc), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
absolute_path_from_handle :: proc(fd: Handle) -> (string, Errno) {
|
||||
absolute_path_from_handle :: proc(fd: Handle) -> (path: string, err: Errno) {
|
||||
buf: [DARWIN_MAXPATHLEN]byte
|
||||
_, err := fcntl(int(fd), F_GETPATH, int(uintptr(&buf[0])))
|
||||
if err != ERROR_NONE {
|
||||
return "", err
|
||||
}
|
||||
|
||||
path := strings.clone_from_cstring(cstring(&buf[0]))
|
||||
return path, err
|
||||
_ = fcntl(int(fd), F_GETPATH, int(uintptr(&buf[0]))) or_return
|
||||
return strings.clone_from_cstring(cstring(&buf[0]))
|
||||
}
|
||||
|
||||
absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Errno) {
|
||||
@@ -1002,7 +990,7 @@ absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Errno) {
|
||||
path_cstr := cast(cstring)path_ptr
|
||||
path = strings.clone(string(path_cstr))
|
||||
|
||||
return path, ERROR_NONE
|
||||
return path, nil
|
||||
}
|
||||
|
||||
access :: proc(path: string, mask: int) -> bool {
|
||||
@@ -1162,7 +1150,7 @@ socket :: proc(domain: int, type: int, protocol: int) -> (Socket, Errno) {
|
||||
if result < 0 {
|
||||
return 0, Errno(get_last_error())
|
||||
}
|
||||
return Socket(result), ERROR_NONE
|
||||
return Socket(result), nil
|
||||
}
|
||||
|
||||
connect :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Errno) {
|
||||
@@ -1186,7 +1174,7 @@ accept :: proc(sd: Socket, addr: ^SOCKADDR, len: rawptr) -> (Socket, Errno) {
|
||||
if result < 0 {
|
||||
return 0, Errno(get_last_error())
|
||||
}
|
||||
return Socket(result), ERROR_NONE
|
||||
return Socket(result), nil
|
||||
}
|
||||
|
||||
listen :: proc(sd: Socket, backlog: int) -> (Errno) {
|
||||
@@ -1218,7 +1206,7 @@ recvfrom :: proc(sd: Socket, data: []byte, flags: int, addr: ^SOCKADDR, addr_siz
|
||||
if result < 0 {
|
||||
return 0, Errno(get_last_error())
|
||||
}
|
||||
return u32(result), ERROR_NONE
|
||||
return u32(result), nil
|
||||
}
|
||||
|
||||
recv :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Errno) {
|
||||
@@ -1226,7 +1214,7 @@ recv :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Errno) {
|
||||
if result < 0 {
|
||||
return 0, Errno(get_last_error())
|
||||
}
|
||||
return u32(result), ERROR_NONE
|
||||
return u32(result), nil
|
||||
}
|
||||
|
||||
sendto :: proc(sd: Socket, data: []u8, flags: int, addr: ^SOCKADDR, addrlen: socklen_t) -> (u32, Errno) {
|
||||
@@ -1234,7 +1222,7 @@ sendto :: proc(sd: Socket, data: []u8, flags: int, addr: ^SOCKADDR, addrlen: soc
|
||||
if result < 0 {
|
||||
return 0, Errno(get_last_error())
|
||||
}
|
||||
return u32(result), ERROR_NONE
|
||||
return u32(result), nil
|
||||
}
|
||||
|
||||
send :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Errno) {
|
||||
@@ -1242,7 +1230,7 @@ send :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Errno) {
|
||||
if result < 0 {
|
||||
return 0, Errno(get_last_error())
|
||||
}
|
||||
return u32(result), ERROR_NONE
|
||||
return u32(result), nil
|
||||
}
|
||||
|
||||
shutdown :: proc(sd: Socket, how: int) -> (Errno) {
|
||||
@@ -1258,5 +1246,5 @@ fcntl :: proc(fd: int, cmd: int, arg: int) -> (int, Errno) {
|
||||
if result < 0 {
|
||||
return 0, Errno(get_last_error())
|
||||
}
|
||||
return int(result), ERROR_NONE
|
||||
return int(result), nil
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import "core:sys/es"
|
||||
Handle :: distinct int
|
||||
_Platform_Error :: enum i32 {NONE}
|
||||
|
||||
ERROR_NONE :: Errno(es.SUCCESS)
|
||||
// ERROR_NONE :: Errno(es.SUCCESS)
|
||||
|
||||
O_RDONLY :: 0x1
|
||||
O_WRONLY :: 0x2
|
||||
|
||||
+26
-28
@@ -430,7 +430,7 @@ open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0) -> (Handle, Err
|
||||
if handle == -1 {
|
||||
return INVALID_HANDLE, Errno(get_last_error())
|
||||
}
|
||||
return handle, ERROR_NONE
|
||||
return handle, nil
|
||||
}
|
||||
|
||||
close :: proc(fd: Handle) -> Errno {
|
||||
@@ -455,12 +455,12 @@ read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if bytes_read == -1 {
|
||||
return -1, Errno(get_last_error())
|
||||
}
|
||||
return int(bytes_read), ERROR_NONE
|
||||
return int(bytes_read), nil
|
||||
}
|
||||
|
||||
write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
to_write := min(c.size_t(len(data)), MAX_RW)
|
||||
@@ -468,7 +468,7 @@ write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if bytes_written == -1 {
|
||||
return -1, Errno(get_last_error())
|
||||
}
|
||||
return int(bytes_written), ERROR_NONE
|
||||
return int(bytes_written), nil
|
||||
}
|
||||
|
||||
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||
@@ -476,15 +476,14 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||
if res == -1 {
|
||||
return -1, Errno(get_last_error())
|
||||
}
|
||||
return res, ERROR_NONE
|
||||
return res, nil
|
||||
}
|
||||
|
||||
file_size :: proc(fd: Handle) -> (i64, Errno) {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
return -1, err
|
||||
}
|
||||
return s.size, ERROR_NONE
|
||||
file_size :: proc(fd: Handle) -> (size: i64, err: Errno) {
|
||||
size = -1
|
||||
s := _fstat(fd) or_return
|
||||
size = s.size
|
||||
return
|
||||
}
|
||||
|
||||
rename :: proc(old_path, new_path: string) -> Errno {
|
||||
@@ -530,7 +529,7 @@ remove_directory :: proc(path: string) -> Errno {
|
||||
|
||||
is_file_handle :: proc(fd: Handle) -> bool {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISREG(s.mode)
|
||||
@@ -544,7 +543,7 @@ is_file_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||
} else {
|
||||
s, err = _lstat(path)
|
||||
}
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISREG(s.mode)
|
||||
@@ -552,7 +551,7 @@ is_file_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||
|
||||
is_dir_handle :: proc(fd: Handle) -> bool {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISDIR(s.mode)
|
||||
@@ -566,7 +565,7 @@ is_dir_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||
} else {
|
||||
s, err = _lstat(path)
|
||||
}
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISDIR(s.mode)
|
||||
@@ -587,20 +586,20 @@ last_write_time_by_name :: proc(name: string) -> File_Time {}
|
||||
*/
|
||||
last_write_time :: proc(fd: Handle) -> (File_Time, Errno) {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
||||
return File_Time(modified), ERROR_NONE
|
||||
return File_Time(modified), nil
|
||||
}
|
||||
|
||||
last_write_time_by_name :: proc(name: string) -> (File_Time, Errno) {
|
||||
s, err := _stat(name)
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
||||
return File_Time(modified), ERROR_NONE
|
||||
return File_Time(modified), nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -612,7 +611,7 @@ _stat :: proc(path: string) -> (OS_Stat, Errno) {
|
||||
if result == -1 {
|
||||
return s, Errno(get_last_error())
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -626,7 +625,7 @@ _lstat :: proc(path: string) -> (OS_Stat, Errno) {
|
||||
if res == -1 {
|
||||
return s, Errno(get_last_error())
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -636,7 +635,7 @@ _fstat :: proc(fd: Handle) -> (OS_Stat, Errno) {
|
||||
if result == -1 {
|
||||
return s, Errno(get_last_error())
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -645,7 +644,7 @@ _fdopendir :: proc(fd: Handle) -> (Dir, Errno) {
|
||||
if dirp == cast(Dir)nil {
|
||||
return nil, Errno(get_last_error())
|
||||
}
|
||||
return dirp, ERROR_NONE
|
||||
return dirp, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -671,7 +670,6 @@ _readdir :: proc(dirp: Dir) -> (entry: Dirent, err: Errno, end_of_stream: bool)
|
||||
err = Errno(get_last_error())
|
||||
return
|
||||
}
|
||||
err = ERROR_NONE
|
||||
|
||||
if result == nil {
|
||||
end_of_stream = true
|
||||
@@ -699,7 +697,7 @@ _readlink :: proc(path: string) -> (string, Errno) {
|
||||
delete(buf)
|
||||
buf = make([]byte, bufsz)
|
||||
} else {
|
||||
return strings.string_from_ptr(&buf[0], rc), ERROR_NONE
|
||||
return strings.string_from_ptr(&buf[0], rc), nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -725,7 +723,7 @@ absolute_path_from_handle :: proc(fd: Handle) -> (string, Errno) {
|
||||
}
|
||||
|
||||
path := strings.clone_from_cstring_bounded(cast(cstring)&kinfo.path[0], len(kinfo.path))
|
||||
return path, ERROR_NONE
|
||||
return path, nil
|
||||
}
|
||||
|
||||
absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Errno) {
|
||||
@@ -746,7 +744,7 @@ absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Errno) {
|
||||
|
||||
path = strings.clone(string(cstring(path_ptr)))
|
||||
|
||||
return path, ERROR_NONE
|
||||
return path, nil
|
||||
}
|
||||
|
||||
access :: proc(path: string, mask: int) -> (bool, Errno) {
|
||||
@@ -757,7 +755,7 @@ access :: proc(path: string, mask: int) -> (bool, Errno) {
|
||||
if result == -1 {
|
||||
return false, Errno(get_last_error())
|
||||
}
|
||||
return true, ERROR_NONE
|
||||
return true, nil
|
||||
}
|
||||
|
||||
lookup_env :: proc(key: string, allocator := context.allocator) -> (value: string, found: bool) {
|
||||
|
||||
+15
-16
@@ -190,7 +190,7 @@ fork :: proc() -> (Pid, Errno) {
|
||||
if pid == -1 {
|
||||
return Pid(-1), Errno(get_last_error())
|
||||
}
|
||||
return Pid(pid), ERROR_NONE
|
||||
return Pid(pid), nil
|
||||
}
|
||||
|
||||
open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0) -> (Handle, Errno) {
|
||||
@@ -200,7 +200,7 @@ open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0) -> (Handle, Err
|
||||
if handle == -1 {
|
||||
return INVALID_HANDLE, Errno(get_last_error())
|
||||
}
|
||||
return handle, ERROR_NONE
|
||||
return handle, nil
|
||||
}
|
||||
|
||||
close :: proc(fd: Handle) -> Errno {
|
||||
@@ -224,12 +224,12 @@ read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if bytes_read == -1 {
|
||||
return -1, Errno(get_last_error())
|
||||
}
|
||||
return int(bytes_read), ERROR_NONE
|
||||
return int(bytes_read), nil
|
||||
}
|
||||
|
||||
write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
to_write := min(c.size_t(len(data)), MAX_RW)
|
||||
@@ -237,7 +237,7 @@ write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if bytes_written == -1 {
|
||||
return -1, Errno(get_last_error())
|
||||
}
|
||||
return int(bytes_written), ERROR_NONE
|
||||
return int(bytes_written), nil
|
||||
}
|
||||
|
||||
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||
@@ -245,15 +245,15 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||
if res == -1 {
|
||||
return -1, Errno(get_last_error())
|
||||
}
|
||||
return res, ERROR_NONE
|
||||
return res, nil
|
||||
}
|
||||
|
||||
file_size :: proc(fd: Handle) -> (i64, Errno) {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
return s.size, ERROR_NONE
|
||||
return s.size, nil
|
||||
}
|
||||
|
||||
// "Argv" arguments converted to Odin strings
|
||||
@@ -278,7 +278,7 @@ _stat :: proc(path: string) -> (OS_Stat, Errno) {
|
||||
if res == -1 {
|
||||
return s, Errno(get_last_error())
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -292,7 +292,7 @@ _lstat :: proc(path: string) -> (OS_Stat, Errno) {
|
||||
if res == -1 {
|
||||
return s, Errno(get_last_error())
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -303,7 +303,7 @@ _fstat :: proc(fd: Handle) -> (OS_Stat, Errno) {
|
||||
if res == -1 {
|
||||
return s, Errno(get_last_error())
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -312,7 +312,7 @@ _fdopendir :: proc(fd: Handle) -> (Dir, Errno) {
|
||||
if dirp == cast(Dir)nil {
|
||||
return nil, Errno(get_last_error())
|
||||
}
|
||||
return dirp, ERROR_NONE
|
||||
return dirp, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -338,7 +338,6 @@ _readdir :: proc(dirp: Dir) -> (entry: Dirent, err: Errno, end_of_stream: bool)
|
||||
err = Errno(get_last_error())
|
||||
return
|
||||
}
|
||||
err = ERROR_NONE
|
||||
|
||||
if result == nil {
|
||||
end_of_stream = true
|
||||
@@ -365,7 +364,7 @@ _readlink :: proc(path: string) -> (string, Errno) {
|
||||
delete(buf)
|
||||
buf = make([]byte, bufsz)
|
||||
} else {
|
||||
return strings.string_from_ptr(&buf[0], rc), ERROR_NONE
|
||||
return strings.string_from_ptr(&buf[0], rc), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -392,7 +391,7 @@ absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Errno) {
|
||||
path_cstr := cstring(path_ptr)
|
||||
path = strings.clone(string(path_cstr))
|
||||
|
||||
return path, ERROR_NONE
|
||||
return path, nil
|
||||
}
|
||||
|
||||
access :: proc(path: string, mask: int) -> (bool, Errno) {
|
||||
@@ -402,7 +401,7 @@ access :: proc(path: string, mask: int) -> (bool, Errno) {
|
||||
if res == -1 {
|
||||
return false, Errno(get_last_error())
|
||||
}
|
||||
return true, ERROR_NONE
|
||||
return true, nil
|
||||
}
|
||||
|
||||
lookup_env :: proc(key: string, allocator := context.allocator) -> (value: string, found: bool) {
|
||||
|
||||
+39
-45
@@ -537,7 +537,7 @@ fork :: proc() -> (Pid, Errno) {
|
||||
if pid == -1 {
|
||||
return -1, _get_errno(pid)
|
||||
}
|
||||
return Pid(pid), ERROR_NONE
|
||||
return Pid(pid), nil
|
||||
}
|
||||
|
||||
execvp :: proc(path: string, args: []string) -> Errno {
|
||||
@@ -562,7 +562,7 @@ open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0o000) -> (Handle,
|
||||
if handle < 0 {
|
||||
return INVALID_HANDLE, _get_errno(handle)
|
||||
}
|
||||
return Handle(handle), ERROR_NONE
|
||||
return Handle(handle), nil
|
||||
}
|
||||
|
||||
close :: proc(fd: Handle) -> Errno {
|
||||
@@ -580,7 +580,7 @@ MAX_RW :: 1 << 30
|
||||
|
||||
read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
to_read := min(uint(len(data)), MAX_RW)
|
||||
@@ -589,12 +589,12 @@ read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if bytes_read < 0 {
|
||||
return -1, _get_errno(bytes_read)
|
||||
}
|
||||
return bytes_read, ERROR_NONE
|
||||
return bytes_read, nil
|
||||
}
|
||||
|
||||
write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
to_write := min(uint(len(data)), MAX_RW)
|
||||
@@ -603,12 +603,12 @@ write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if bytes_written < 0 {
|
||||
return -1, _get_errno(bytes_written)
|
||||
}
|
||||
return bytes_written, ERROR_NONE
|
||||
return bytes_written, nil
|
||||
}
|
||||
|
||||
read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
to_read := min(uint(len(data)), MAX_RW)
|
||||
@@ -617,12 +617,12 @@ read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
||||
if bytes_read < 0 {
|
||||
return -1, _get_errno(bytes_read)
|
||||
}
|
||||
return bytes_read, ERROR_NONE
|
||||
return bytes_read, nil
|
||||
}
|
||||
|
||||
write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
to_write := min(uint(len(data)), MAX_RW)
|
||||
@@ -631,7 +631,7 @@ write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
||||
if bytes_written < 0 {
|
||||
return -1, _get_errno(bytes_written)
|
||||
}
|
||||
return bytes_written, ERROR_NONE
|
||||
return bytes_written, nil
|
||||
}
|
||||
|
||||
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||
@@ -639,7 +639,7 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||
if res < 0 {
|
||||
return -1, _get_errno(int(res))
|
||||
}
|
||||
return i64(res), ERROR_NONE
|
||||
return i64(res), nil
|
||||
}
|
||||
|
||||
file_size :: proc(fd: Handle) -> (i64, Errno) {
|
||||
@@ -649,7 +649,7 @@ file_size :: proc(fd: Handle) -> (i64, Errno) {
|
||||
if result < 0 {
|
||||
return 0, _get_errno(result)
|
||||
}
|
||||
return max(s.size, 0), ERROR_NONE
|
||||
return max(s.size, 0), nil
|
||||
}
|
||||
|
||||
rename :: proc(old_path, new_path: string) -> Errno {
|
||||
@@ -679,7 +679,7 @@ remove_directory :: proc(path: string) -> Errno {
|
||||
|
||||
is_file_handle :: proc(fd: Handle) -> bool {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISREG(s.mode)
|
||||
@@ -693,7 +693,7 @@ is_file_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||
} else {
|
||||
s, err = _lstat(path)
|
||||
}
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISREG(s.mode)
|
||||
@@ -702,7 +702,7 @@ is_file_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||
|
||||
is_dir_handle :: proc(fd: Handle) -> bool {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISDIR(s.mode)
|
||||
@@ -716,7 +716,7 @@ is_dir_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||
} else {
|
||||
s, err = _lstat(path)
|
||||
}
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISDIR(s.mode)
|
||||
@@ -742,22 +742,16 @@ stderr: Handle = 2
|
||||
last_write_time :: proc(fd: Handle) -> File_Time {}
|
||||
last_write_time_by_name :: proc(name: string) -> File_Time {}
|
||||
*/
|
||||
last_write_time :: proc(fd: Handle) -> (File_Time, Errno) {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
return 0, err
|
||||
}
|
||||
last_write_time :: proc(fd: Handle) -> (time: File_Time, err: Errno) {
|
||||
s := _fstat(fd) or_return
|
||||
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
||||
return File_Time(modified), ERROR_NONE
|
||||
return File_Time(modified), nil
|
||||
}
|
||||
|
||||
last_write_time_by_name :: proc(name: string) -> (File_Time, Errno) {
|
||||
s, err := _stat(name)
|
||||
if err != ERROR_NONE {
|
||||
return 0, err
|
||||
}
|
||||
last_write_time_by_name :: proc(name: string) -> (time: File_Time, err: Errno) {
|
||||
s := _stat(name) or_return
|
||||
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
||||
return File_Time(modified), ERROR_NONE
|
||||
return File_Time(modified), nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -771,7 +765,7 @@ _stat :: proc(path: string) -> (OS_Stat, Errno) {
|
||||
if result < 0 {
|
||||
return s, _get_errno(result)
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -785,7 +779,7 @@ _lstat :: proc(path: string) -> (OS_Stat, Errno) {
|
||||
if result < 0 {
|
||||
return s, _get_errno(result)
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -796,7 +790,7 @@ _fstat :: proc(fd: Handle) -> (OS_Stat, Errno) {
|
||||
if result < 0 {
|
||||
return s, _get_errno(result)
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -805,7 +799,7 @@ _fdopendir :: proc(fd: Handle) -> (Dir, Errno) {
|
||||
if dirp == cast(Dir)nil {
|
||||
return nil, Errno(get_last_error())
|
||||
}
|
||||
return dirp, ERROR_NONE
|
||||
return dirp, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -831,7 +825,7 @@ _readdir :: proc(dirp: Dir) -> (entry: Dirent, err: Errno, end_of_stream: bool)
|
||||
err = Errno(get_last_error())
|
||||
return
|
||||
}
|
||||
err = ERROR_NONE
|
||||
err = nil
|
||||
|
||||
if result == nil {
|
||||
end_of_stream = true
|
||||
@@ -860,7 +854,7 @@ _readlink :: proc(path: string) -> (string, Errno) {
|
||||
delete(buf)
|
||||
buf = make([]byte, bufsz)
|
||||
} else {
|
||||
return strings.string_from_ptr(&buf[0], rc), ERROR_NONE
|
||||
return strings.string_from_ptr(&buf[0], rc), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -892,7 +886,7 @@ absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Errno) {
|
||||
|
||||
path = strings.clone(string(cstring(path_ptr)))
|
||||
|
||||
return path, ERROR_NONE
|
||||
return path, nil
|
||||
}
|
||||
|
||||
access :: proc(path: string, mask: int) -> (bool, Errno) {
|
||||
@@ -902,7 +896,7 @@ access :: proc(path: string, mask: int) -> (bool, Errno) {
|
||||
if result < 0 {
|
||||
return false, _get_errno(result)
|
||||
}
|
||||
return true, ERROR_NONE
|
||||
return true, nil
|
||||
}
|
||||
|
||||
lookup_env :: proc(key: string, allocator := context.allocator) -> (value: string, found: bool) {
|
||||
@@ -1034,7 +1028,7 @@ socket :: proc(domain: int, type: int, protocol: int) -> (Socket, Errno) {
|
||||
if result < 0 {
|
||||
return 0, _get_errno(result)
|
||||
}
|
||||
return Socket(result), ERROR_NONE
|
||||
return Socket(result), nil
|
||||
}
|
||||
|
||||
bind :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Errno) {
|
||||
@@ -1059,7 +1053,7 @@ accept :: proc(sd: Socket, addr: ^SOCKADDR, len: rawptr) -> (Socket, Errno) {
|
||||
if result < 0 {
|
||||
return 0, _get_errno(result)
|
||||
}
|
||||
return Socket(result), ERROR_NONE
|
||||
return Socket(result), nil
|
||||
}
|
||||
|
||||
listen :: proc(sd: Socket, backlog: int) -> (Errno) {
|
||||
@@ -1084,7 +1078,7 @@ recvfrom :: proc(sd: Socket, data: []byte, flags: int, addr: ^SOCKADDR, addr_siz
|
||||
if result < 0 {
|
||||
return 0, _get_errno(int(result))
|
||||
}
|
||||
return u32(result), ERROR_NONE
|
||||
return u32(result), nil
|
||||
}
|
||||
|
||||
recv :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Errno) {
|
||||
@@ -1092,7 +1086,7 @@ recv :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Errno) {
|
||||
if result < 0 {
|
||||
return 0, _get_errno(int(result))
|
||||
}
|
||||
return u32(result), ERROR_NONE
|
||||
return u32(result), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1101,7 +1095,7 @@ sendto :: proc(sd: Socket, data: []u8, flags: int, addr: ^SOCKADDR, addrlen: soc
|
||||
if result < 0 {
|
||||
return 0, _get_errno(int(result))
|
||||
}
|
||||
return u32(result), ERROR_NONE
|
||||
return u32(result), nil
|
||||
}
|
||||
|
||||
send :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Errno) {
|
||||
@@ -1109,7 +1103,7 @@ send :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Errno) {
|
||||
if result < 0 {
|
||||
return 0, _get_errno(int(result))
|
||||
}
|
||||
return u32(result), ERROR_NONE
|
||||
return u32(result), nil
|
||||
}
|
||||
|
||||
shutdown :: proc(sd: Socket, how: int) -> (Errno) {
|
||||
@@ -1125,7 +1119,7 @@ fcntl :: proc(fd: int, cmd: int, arg: int) -> (int, Errno) {
|
||||
if result < 0 {
|
||||
return 0, _get_errno(result)
|
||||
}
|
||||
return result, ERROR_NONE
|
||||
return result, nil
|
||||
}
|
||||
|
||||
poll :: proc(fds: []pollfd, timeout: int) -> (int, Errno) {
|
||||
@@ -1133,7 +1127,7 @@ poll :: proc(fds: []pollfd, timeout: int) -> (int, Errno) {
|
||||
if result < 0 {
|
||||
return 0, _get_errno(result)
|
||||
}
|
||||
return result, ERROR_NONE
|
||||
return result, nil
|
||||
}
|
||||
|
||||
ppoll :: proc(fds: []pollfd, timeout: ^unix.timespec, sigmask: ^sigset_t) -> (int, Errno) {
|
||||
@@ -1141,5 +1135,5 @@ ppoll :: proc(fds: []pollfd, timeout: ^unix.timespec, sigmask: ^sigset_t) -> (in
|
||||
if result < 0 {
|
||||
return 0, _get_errno(result)
|
||||
}
|
||||
return result, ERROR_NONE
|
||||
return result, nil
|
||||
}
|
||||
|
||||
+32
-44
@@ -488,7 +488,7 @@ open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0) -> (Handle, Err
|
||||
if handle == -1 {
|
||||
return INVALID_HANDLE, Errno(get_last_error())
|
||||
}
|
||||
return handle, ERROR_NONE
|
||||
return handle, nil
|
||||
}
|
||||
|
||||
close :: proc(fd: Handle) -> Errno {
|
||||
@@ -509,12 +509,12 @@ read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if bytes_read == -1 {
|
||||
return -1, Errno(get_last_error())
|
||||
}
|
||||
return int(bytes_read), ERROR_NONE
|
||||
return int(bytes_read), nil
|
||||
}
|
||||
|
||||
write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
to_write := min(c.size_t(len(data)), MAX_RW)
|
||||
@@ -522,7 +522,7 @@ write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if bytes_written == -1 {
|
||||
return -1, Errno(get_last_error())
|
||||
}
|
||||
return int(bytes_written), ERROR_NONE
|
||||
return int(bytes_written), nil
|
||||
}
|
||||
|
||||
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||
@@ -530,15 +530,14 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||
if res == -1 {
|
||||
return -1, Errno(get_last_error())
|
||||
}
|
||||
return res, ERROR_NONE
|
||||
return res, nil
|
||||
}
|
||||
|
||||
file_size :: proc(fd: Handle) -> (i64, Errno) {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
return -1, err
|
||||
}
|
||||
return s.size, ERROR_NONE
|
||||
file_size :: proc(fd: Handle) -> (size: i64, err: Errno) {
|
||||
size = -1
|
||||
s := _fstat(fd) or_return
|
||||
size = s.size
|
||||
return
|
||||
}
|
||||
|
||||
rename :: proc(old_path, new_path: string) -> Errno {
|
||||
@@ -584,7 +583,7 @@ remove_directory :: proc(path: string) -> Errno {
|
||||
|
||||
is_file_handle :: proc(fd: Handle) -> bool {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISREG(s.mode)
|
||||
@@ -598,7 +597,7 @@ is_file_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||
} else {
|
||||
s, err = _lstat(path)
|
||||
}
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISREG(s.mode)
|
||||
@@ -606,7 +605,7 @@ is_file_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||
|
||||
is_dir_handle :: proc(fd: Handle) -> bool {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISDIR(s.mode)
|
||||
@@ -620,7 +619,7 @@ is_dir_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||
} else {
|
||||
s, err = _lstat(path)
|
||||
}
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISDIR(s.mode)
|
||||
@@ -641,7 +640,7 @@ fcntl :: proc(fd: int, cmd: int, arg: int) -> (int, Errno) {
|
||||
if result < 0 {
|
||||
return 0, Errno(get_last_error())
|
||||
}
|
||||
return int(result), ERROR_NONE
|
||||
return int(result), nil
|
||||
}
|
||||
|
||||
// NOTE(bill): Uses startup to initialize it
|
||||
@@ -650,22 +649,16 @@ stdin: Handle = 0
|
||||
stdout: Handle = 1
|
||||
stderr: Handle = 2
|
||||
|
||||
last_write_time :: proc(fd: Handle) -> (File_Time, Errno) {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
return 0, err
|
||||
}
|
||||
last_write_time :: proc(fd: Handle) -> (time: File_Time, err: Errno) {
|
||||
s := _fstat(fd) or_return
|
||||
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
||||
return File_Time(modified), ERROR_NONE
|
||||
return File_Time(modified), nil
|
||||
}
|
||||
|
||||
last_write_time_by_name :: proc(name: string) -> (File_Time, Errno) {
|
||||
s, err := _stat(name)
|
||||
if err != ERROR_NONE {
|
||||
return 0, err
|
||||
}
|
||||
last_write_time_by_name :: proc(name: string) -> (time: File_Time, err: Errno) {
|
||||
s := _stat(name) or_return
|
||||
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
||||
return File_Time(modified), ERROR_NONE
|
||||
return File_Time(modified), nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -677,7 +670,7 @@ _stat :: proc(path: string) -> (OS_Stat, Errno) {
|
||||
if result == -1 {
|
||||
return s, Errno(get_last_error())
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -691,7 +684,7 @@ _lstat :: proc(path: string) -> (OS_Stat, Errno) {
|
||||
if res == -1 {
|
||||
return s, Errno(get_last_error())
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -701,7 +694,7 @@ _fstat :: proc(fd: Handle) -> (OS_Stat, Errno) {
|
||||
if result == -1 {
|
||||
return s, Errno(get_last_error())
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -710,7 +703,7 @@ _fdopendir :: proc(fd: Handle) -> (Dir, Errno) {
|
||||
if dirp == cast(Dir)nil {
|
||||
return nil, Errno(get_last_error())
|
||||
}
|
||||
return dirp, ERROR_NONE
|
||||
return dirp, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -736,7 +729,7 @@ _readdir :: proc(dirp: Dir) -> (entry: Dirent, err: Errno, end_of_stream: bool)
|
||||
err = Errno(get_last_error())
|
||||
return
|
||||
}
|
||||
err = ERROR_NONE
|
||||
err = nil
|
||||
|
||||
if result == nil {
|
||||
end_of_stream = true
|
||||
@@ -764,22 +757,17 @@ _readlink :: proc(path: string) -> (string, Errno) {
|
||||
delete(buf)
|
||||
buf = make([]byte, bufsz)
|
||||
} else {
|
||||
return strings.string_from_ptr(&buf[0], rc), ERROR_NONE
|
||||
return strings.string_from_ptr(&buf[0], rc), nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", Errno{}
|
||||
}
|
||||
|
||||
absolute_path_from_handle :: proc(fd: Handle) -> (string, Errno) {
|
||||
absolute_path_from_handle :: proc(fd: Handle) -> (path: string, err: Errno) {
|
||||
buf: [MAX_PATH]byte
|
||||
_, err := fcntl(int(fd), F_GETPATH, int(uintptr(&buf[0])))
|
||||
if err != ERROR_NONE {
|
||||
return "", err
|
||||
}
|
||||
|
||||
path := strings.clone_from_cstring(cstring(&buf[0]))
|
||||
return path, err
|
||||
_ = fcntl(int(fd), F_GETPATH, int(uintptr(&buf[0]))) or_return
|
||||
return strings.clone_from_cstring(cstring(&buf[0]))
|
||||
}
|
||||
|
||||
absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Errno) {
|
||||
@@ -799,7 +787,7 @@ absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Errno) {
|
||||
|
||||
path = strings.clone(string(cstring(path_ptr)))
|
||||
|
||||
return path, ERROR_NONE
|
||||
return path, nil
|
||||
}
|
||||
|
||||
access :: proc(path: string, mask: int) -> (bool, Errno) {
|
||||
@@ -810,7 +798,7 @@ access :: proc(path: string, mask: int) -> (bool, Errno) {
|
||||
if result == -1 {
|
||||
return false, Errno(get_last_error())
|
||||
}
|
||||
return true, ERROR_NONE
|
||||
return true, nil
|
||||
}
|
||||
|
||||
lookup_env :: proc(key: string, allocator := context.allocator) -> (value: string, found: bool) {
|
||||
|
||||
+29
-36
@@ -401,7 +401,7 @@ fork :: proc() -> (Pid, Errno) {
|
||||
if pid == -1 {
|
||||
return Pid(-1), Errno(get_last_error())
|
||||
}
|
||||
return Pid(pid), ERROR_NONE
|
||||
return Pid(pid), nil
|
||||
}
|
||||
|
||||
open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0) -> (Handle, Errno) {
|
||||
@@ -411,7 +411,7 @@ open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0) -> (Handle, Err
|
||||
if handle == -1 {
|
||||
return INVALID_HANDLE, Errno(get_last_error())
|
||||
}
|
||||
return handle, ERROR_NONE
|
||||
return handle, nil
|
||||
}
|
||||
|
||||
close :: proc(fd: Handle) -> Errno {
|
||||
@@ -436,12 +436,12 @@ read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if bytes_read == -1 {
|
||||
return -1, Errno(get_last_error())
|
||||
}
|
||||
return int(bytes_read), ERROR_NONE
|
||||
return int(bytes_read), nil
|
||||
}
|
||||
|
||||
write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
to_write := min(c.size_t(len(data)), MAX_RW)
|
||||
@@ -449,7 +449,7 @@ write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
if bytes_written == -1 {
|
||||
return -1, Errno(get_last_error())
|
||||
}
|
||||
return int(bytes_written), ERROR_NONE
|
||||
return int(bytes_written), nil
|
||||
}
|
||||
|
||||
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||
@@ -457,15 +457,14 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||
if res == -1 {
|
||||
return -1, Errno(get_last_error())
|
||||
}
|
||||
return res, ERROR_NONE
|
||||
return res, nil
|
||||
}
|
||||
|
||||
file_size :: proc(fd: Handle) -> (i64, Errno) {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
return -1, err
|
||||
}
|
||||
return s.size, ERROR_NONE
|
||||
file_size :: proc(fd: Handle) -> (size: i64, err: Errno) {
|
||||
size = -1
|
||||
s := _fstat(fd) or_return
|
||||
size = s.size
|
||||
return
|
||||
}
|
||||
|
||||
rename :: proc(old_path, new_path: string) -> Errno {
|
||||
@@ -511,7 +510,7 @@ remove_directory :: proc(path: string) -> Errno {
|
||||
|
||||
is_file_handle :: proc(fd: Handle) -> bool {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISREG(s.mode)
|
||||
@@ -525,7 +524,7 @@ is_file_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||
} else {
|
||||
s, err = _lstat(path)
|
||||
}
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISREG(s.mode)
|
||||
@@ -533,7 +532,7 @@ is_file_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||
|
||||
is_dir_handle :: proc(fd: Handle) -> bool {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISDIR(s.mode)
|
||||
@@ -547,7 +546,7 @@ is_dir_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||
} else {
|
||||
s, err = _lstat(path)
|
||||
}
|
||||
if err != ERROR_NONE {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return S_ISDIR(s.mode)
|
||||
@@ -566,22 +565,16 @@ stderr: Handle = 2
|
||||
last_write_time :: proc(fd: Handle) -> File_Time {}
|
||||
last_write_time_by_name :: proc(name: string) -> File_Time {}
|
||||
*/
|
||||
last_write_time :: proc(fd: Handle) -> (File_Time, Errno) {
|
||||
s, err := _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
return 0, err
|
||||
}
|
||||
last_write_time :: proc(fd: Handle) -> (time: File_Time, err: Errno) {
|
||||
s := _fstat(fd) or_return
|
||||
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
||||
return File_Time(modified), ERROR_NONE
|
||||
return File_Time(modified), nil
|
||||
}
|
||||
|
||||
last_write_time_by_name :: proc(name: string) -> (File_Time, Errno) {
|
||||
s, err := _stat(name)
|
||||
if err != ERROR_NONE {
|
||||
return 0, err
|
||||
}
|
||||
last_write_time_by_name :: proc(name: string) -> (time: File_Time, err: Errno) {
|
||||
s := _stat(name) or_return
|
||||
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
||||
return File_Time(modified), ERROR_NONE
|
||||
return File_Time(modified), nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -595,7 +588,7 @@ _stat :: proc(path: string) -> (OS_Stat, Errno) {
|
||||
if res == -1 {
|
||||
return s, Errno(get_last_error())
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -609,7 +602,7 @@ _lstat :: proc(path: string) -> (OS_Stat, Errno) {
|
||||
if res == -1 {
|
||||
return s, Errno(get_last_error())
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -620,7 +613,7 @@ _fstat :: proc(fd: Handle) -> (OS_Stat, Errno) {
|
||||
if res == -1 {
|
||||
return s, Errno(get_last_error())
|
||||
}
|
||||
return s, ERROR_NONE
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -629,7 +622,7 @@ _fdopendir :: proc(fd: Handle) -> (Dir, Errno) {
|
||||
if dirp == cast(Dir)nil {
|
||||
return nil, Errno(get_last_error())
|
||||
}
|
||||
return dirp, ERROR_NONE
|
||||
return dirp, nil
|
||||
}
|
||||
|
||||
@private
|
||||
@@ -655,7 +648,7 @@ _readdir :: proc(dirp: Dir) -> (entry: Dirent, err: Errno, end_of_stream: bool)
|
||||
err = Errno(get_last_error())
|
||||
return
|
||||
}
|
||||
err = ERROR_NONE
|
||||
err = nil
|
||||
|
||||
if result == nil {
|
||||
end_of_stream = true
|
||||
@@ -682,7 +675,7 @@ _readlink :: proc(path: string) -> (string, Errno) {
|
||||
delete(buf)
|
||||
buf = make([]byte, bufsz)
|
||||
} else {
|
||||
return strings.string_from_ptr(&buf[0], rc), ERROR_NONE
|
||||
return strings.string_from_ptr(&buf[0], rc), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -709,7 +702,7 @@ absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Errno) {
|
||||
|
||||
path = strings.clone(string(cstring(path_ptr)))
|
||||
|
||||
return path, ERROR_NONE
|
||||
return path, nil
|
||||
}
|
||||
|
||||
access :: proc(path: string, mask: int) -> (bool, Errno) {
|
||||
@@ -719,7 +712,7 @@ access :: proc(path: string, mask: int) -> (bool, Errno) {
|
||||
if res == -1 {
|
||||
return false, Errno(get_last_error())
|
||||
}
|
||||
return true, ERROR_NONE
|
||||
return true, nil
|
||||
}
|
||||
|
||||
lookup_env :: proc(key: string, allocator := context.allocator) -> (value: string, found: bool) {
|
||||
|
||||
@@ -8,8 +8,6 @@ _Platform_Error :: wasi.errno_t
|
||||
|
||||
INVALID_HANDLE :: -1
|
||||
|
||||
// ERROR_NONE :: Errno(wasi.errno_t.SUCCESS) // that is a weird error code. Probably better to remap it
|
||||
|
||||
O_RDONLY :: 0x00000
|
||||
O_WRONLY :: 0x00001
|
||||
O_RDWR :: 0x00002
|
||||
|
||||
+9
-32
@@ -101,54 +101,31 @@ path_base :: proc(path: string) -> string {
|
||||
|
||||
|
||||
lstat :: proc(name: string, allocator := context.allocator) -> (fi: File_Info, err: Errno) {
|
||||
|
||||
context.allocator = allocator
|
||||
|
||||
s: OS_Stat
|
||||
s, err = _lstat(name)
|
||||
if err != ERROR_NONE {
|
||||
return fi, err
|
||||
}
|
||||
s := _lstat(name) or_return
|
||||
_fill_file_info_from_stat(&fi, s)
|
||||
fi.fullpath, err = absolute_path_from_relative(name)
|
||||
if err != ERROR_NONE {
|
||||
return
|
||||
}
|
||||
fi.fullpath = absolute_path_from_relative(name) or_return
|
||||
fi.name = path_base(fi.fullpath)
|
||||
return fi, ERROR_NONE
|
||||
return
|
||||
}
|
||||
|
||||
stat :: proc(name: string, allocator := context.allocator) -> (fi: File_Info, err: Errno) {
|
||||
context.allocator = allocator
|
||||
|
||||
s: OS_Stat
|
||||
s, err = _stat(name)
|
||||
if err != ERROR_NONE {
|
||||
return fi, err
|
||||
}
|
||||
s := _stat(name) or_return
|
||||
_fill_file_info_from_stat(&fi, s)
|
||||
fi.fullpath, err = absolute_path_from_relative(name)
|
||||
if err != ERROR_NONE {
|
||||
return
|
||||
}
|
||||
fi.fullpath = absolute_path_from_relative(name) or_return
|
||||
fi.name = path_base(fi.fullpath)
|
||||
return fi, ERROR_NONE
|
||||
return
|
||||
}
|
||||
|
||||
fstat :: proc(fd: Handle, allocator := context.allocator) -> (fi: File_Info, err: Errno) {
|
||||
|
||||
context.allocator = allocator
|
||||
|
||||
s: OS_Stat
|
||||
s, err = _fstat(fd)
|
||||
if err != ERROR_NONE {
|
||||
return fi, err
|
||||
}
|
||||
s := _fstat(fd) or_return
|
||||
_fill_file_info_from_stat(&fi, s)
|
||||
fi.fullpath, err = absolute_path_from_handle(fd)
|
||||
if err != ERROR_NONE {
|
||||
return
|
||||
}
|
||||
fi.fullpath = absolute_path_from_handle(fd) or_return
|
||||
fi.name = path_base(fi.fullpath)
|
||||
return fi, ERROR_NONE
|
||||
return
|
||||
}
|
||||
|
||||
+10
-10
@@ -22,7 +22,7 @@ full_path_from_name :: proc(name: string, allocator := context.allocator) -> (pa
|
||||
return "", get_last_error()
|
||||
}
|
||||
if n <= u32(len(buf)) {
|
||||
return win32.utf16_to_utf8(buf[:n], allocator) or_else "", ERROR_NONE
|
||||
return win32.utf16_to_utf8(buf[:n], allocator) or_else "", nil
|
||||
}
|
||||
resize(&buf, len(buf)*2)
|
||||
}
|
||||
@@ -83,15 +83,15 @@ stat :: proc(name: string, allocator := context.allocator) -> (File_Info, Errno)
|
||||
return _stat(name, attrs, allocator)
|
||||
}
|
||||
|
||||
fstat :: proc(fd: Handle, allocator := context.allocator) -> (fi: File_Info, errno: Errno) {
|
||||
fstat :: proc(fd: Handle, allocator := context.allocator) -> (fi: File_Info, err: Errno) {
|
||||
if fd == 0 {
|
||||
return {}, ERROR_INVALID_HANDLE
|
||||
err = ERROR_INVALID_HANDLE
|
||||
}
|
||||
context.allocator = allocator
|
||||
|
||||
path, err := cleanpath_from_handle(fd)
|
||||
if err != ERROR_NONE {
|
||||
return {}, err
|
||||
path := cleanpath_from_handle(fd) or_return
|
||||
defer if err != nil {
|
||||
delete(path)
|
||||
}
|
||||
|
||||
h := win32.HANDLE(fd)
|
||||
@@ -99,9 +99,9 @@ fstat :: proc(fd: Handle, allocator := context.allocator) -> (fi: File_Info, err
|
||||
case win32.FILE_TYPE_PIPE, win32.FILE_TYPE_CHAR:
|
||||
fi.name = basename(path)
|
||||
fi.mode |= file_type_mode(h)
|
||||
errno = ERROR_NONE
|
||||
err = nil
|
||||
case:
|
||||
fi, errno = file_info_from_get_file_information_by_handle(path, h)
|
||||
fi = file_info_from_get_file_information_by_handle(path, h) or_return
|
||||
}
|
||||
fi.fullpath = path
|
||||
return
|
||||
@@ -152,7 +152,7 @@ cleanpath_from_handle_u16 :: proc(fd: Handle, allocator: runtime.Allocator) -> (
|
||||
}
|
||||
buf := make([]u16, max(n, win32.DWORD(260))+1, allocator)
|
||||
buf_len := win32.GetFinalPathNameByHandleW(h, raw_data(buf), n, 0)
|
||||
return buf[:buf_len], ERROR_NONE
|
||||
return buf[:buf_len], nil
|
||||
}
|
||||
@(private)
|
||||
cleanpath_from_buf :: proc(buf: []u16) -> string {
|
||||
@@ -296,5 +296,5 @@ file_info_from_get_file_information_by_handle :: proc(path: string, h: win32.HAN
|
||||
|
||||
windows_set_file_info_times(&fi, &d)
|
||||
|
||||
return fi, ERROR_NONE
|
||||
return fi, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user