mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Errno -> Error
This commit is contained in:
@@ -4,7 +4,7 @@ package os
|
|||||||
import "core:strings"
|
import "core:strings"
|
||||||
|
|
||||||
@(require_results)
|
@(require_results)
|
||||||
read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []File_Info, err: Errno) {
|
read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []File_Info, err: Error) {
|
||||||
dirp := _fdopendir(fd) or_return
|
dirp := _fdopendir(fd) or_return
|
||||||
defer _closedir(dirp)
|
defer _closedir(dirp)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import "core:strings"
|
|||||||
import "base:runtime"
|
import "base:runtime"
|
||||||
|
|
||||||
@(require_results)
|
@(require_results)
|
||||||
read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []File_Info, err: Errno) {
|
read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []File_Info, err: Error) {
|
||||||
find_data_to_file_info :: proc(base_path: string, d: ^win32.WIN32_FIND_DATAW) -> (fi: File_Info) {
|
find_data_to_file_info :: proc(base_path: string, d: ^win32.WIN32_FIND_DATAW) -> (fi: File_Info) {
|
||||||
// Ignore "." and ".."
|
// Ignore "." and ".."
|
||||||
if d.cFileName[0] == '.' && d.cFileName[1] == 0 {
|
if d.cFileName[0] == '.' && d.cFileName[1] == 0 {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ get_env :: proc(key: string, allocator := context.allocator) -> (value: string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set_env sets the value of the environment variable named by the key
|
// set_env sets the value of the environment variable named by the key
|
||||||
set_env :: proc(key, value: string) -> Errno {
|
set_env :: proc(key, value: string) -> Error {
|
||||||
k := win32.utf8_to_wstring(key)
|
k := win32.utf8_to_wstring(key)
|
||||||
v := win32.utf8_to_wstring(value)
|
v := win32.utf8_to_wstring(value)
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ set_env :: proc(key, value: string) -> Errno {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// unset_env unsets a single environment variable
|
// unset_env unsets a single environment variable
|
||||||
unset_env :: proc(key: string) -> Errno {
|
unset_env :: proc(key: string) -> Error {
|
||||||
k := win32.utf8_to_wstring(key)
|
k := win32.utf8_to_wstring(key)
|
||||||
if !win32.SetEnvironmentVariableW(k, nil) {
|
if !win32.SetEnvironmentVariableW(k, nil) {
|
||||||
return get_last_error()
|
return get_last_error()
|
||||||
|
|||||||
+25
-25
@@ -9,7 +9,7 @@ is_path_separator :: proc(c: byte) -> bool {
|
|||||||
return c == '/' || c == '\\'
|
return c == '/' || c == '\\'
|
||||||
}
|
}
|
||||||
|
|
||||||
open :: proc(path: string, mode: int = O_RDONLY, perm: int = 0) -> (Handle, Errno) {
|
open :: proc(path: string, mode: int = O_RDONLY, perm: int = 0) -> (Handle, Error) {
|
||||||
if len(path) == 0 {
|
if len(path) == 0 {
|
||||||
return INVALID_HANDLE, General_Error.Not_Exist
|
return INVALID_HANDLE, General_Error.Not_Exist
|
||||||
}
|
}
|
||||||
@@ -58,14 +58,14 @@ open :: proc(path: string, mode: int = O_RDONLY, perm: int = 0) -> (Handle, Errn
|
|||||||
return INVALID_HANDLE, get_last_error()
|
return INVALID_HANDLE, get_last_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
close :: proc(fd: Handle) -> Errno {
|
close :: proc(fd: Handle) -> Error {
|
||||||
if !win32.CloseHandle(win32.HANDLE(fd)) {
|
if !win32.CloseHandle(win32.HANDLE(fd)) {
|
||||||
return get_last_error()
|
return get_last_error()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
flush :: proc(fd: Handle) -> (err: Errno) {
|
flush :: proc(fd: Handle) -> (err: Error) {
|
||||||
if !win32.FlushFileBuffers(win32.HANDLE(fd)) {
|
if !win32.FlushFileBuffers(win32.HANDLE(fd)) {
|
||||||
err = get_last_error()
|
err = get_last_error()
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ flush :: proc(fd: Handle) -> (err: Errno) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
write :: proc(fd: Handle, data: []byte) -> (int, Error) {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@(private="file")
|
@(private="file")
|
||||||
read_console :: proc(handle: win32.HANDLE, b: []byte) -> (n: int, err: Errno) {
|
read_console :: proc(handle: win32.HANDLE, b: []byte) -> (n: int, err: Error) {
|
||||||
if len(b) == 0 {
|
if len(b) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
@@ -147,7 +147,7 @@ read_console :: proc(handle: win32.HANDLE, b: []byte) -> (n: int, err: Errno) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
read :: proc(fd: Handle, data: []byte) -> (total_read: int, err: Errno) {
|
read :: proc(fd: Handle, data: []byte) -> (total_read: int, err: Error) {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
@@ -184,7 +184,7 @@ read :: proc(fd: Handle, data: []byte) -> (total_read: int, err: Errno) {
|
|||||||
return total_read, nil
|
return total_read, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Error) {
|
||||||
w: u32
|
w: u32
|
||||||
switch whence {
|
switch whence {
|
||||||
case 0: w = win32.FILE_BEGIN
|
case 0: w = win32.FILE_BEGIN
|
||||||
@@ -206,9 +206,9 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
|||||||
return i64(hi)<<32 + i64(dw_ptr), nil
|
return i64(hi)<<32 + i64(dw_ptr), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
file_size :: proc(fd: Handle) -> (i64, Errno) {
|
file_size :: proc(fd: Handle) -> (i64, Error) {
|
||||||
length: win32.LARGE_INTEGER
|
length: win32.LARGE_INTEGER
|
||||||
err: Errno
|
err: Error
|
||||||
if !win32.GetFileSizeEx(win32.HANDLE(fd), &length) {
|
if !win32.GetFileSizeEx(win32.HANDLE(fd), &length) {
|
||||||
err = get_last_error()
|
err = get_last_error()
|
||||||
}
|
}
|
||||||
@@ -220,7 +220,7 @@ file_size :: proc(fd: Handle) -> (i64, Errno) {
|
|||||||
MAX_RW :: 1<<30
|
MAX_RW :: 1<<30
|
||||||
|
|
||||||
@(private)
|
@(private)
|
||||||
pread :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
pread :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Error) {
|
||||||
buf := data
|
buf := data
|
||||||
if len(buf) > MAX_RW {
|
if len(buf) > MAX_RW {
|
||||||
buf = buf[:MAX_RW]
|
buf = buf[:MAX_RW]
|
||||||
@@ -236,7 +236,7 @@ pread :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
|||||||
|
|
||||||
h := win32.HANDLE(fd)
|
h := win32.HANDLE(fd)
|
||||||
done: win32.DWORD
|
done: win32.DWORD
|
||||||
e: Errno
|
e: Error
|
||||||
if !win32.ReadFile(h, raw_data(buf), u32(len(buf)), &done, &o) {
|
if !win32.ReadFile(h, raw_data(buf), u32(len(buf)), &done, &o) {
|
||||||
e = get_last_error()
|
e = get_last_error()
|
||||||
done = 0
|
done = 0
|
||||||
@@ -244,7 +244,7 @@ pread :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
|||||||
return int(done), e
|
return int(done), e
|
||||||
}
|
}
|
||||||
@(private)
|
@(private)
|
||||||
pwrite :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
pwrite :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Error) {
|
||||||
buf := data
|
buf := data
|
||||||
if len(buf) > MAX_RW {
|
if len(buf) > MAX_RW {
|
||||||
buf = buf[:MAX_RW]
|
buf = buf[:MAX_RW]
|
||||||
@@ -258,7 +258,7 @@ pwrite :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
|||||||
|
|
||||||
h := win32.HANDLE(fd)
|
h := win32.HANDLE(fd)
|
||||||
done: win32.DWORD
|
done: win32.DWORD
|
||||||
e: Errno
|
e: Error
|
||||||
if !win32.WriteFile(h, raw_data(buf), u32(len(buf)), &done, &o) {
|
if !win32.WriteFile(h, raw_data(buf), u32(len(buf)), &done, &o) {
|
||||||
e = get_last_error()
|
e = get_last_error()
|
||||||
done = 0
|
done = 0
|
||||||
@@ -276,7 +276,7 @@ on Windows, read_at changes the position of the file cursor, on *nix, it does no
|
|||||||
|
|
||||||
will read from the location twice on *nix, and from two different locations on Windows
|
will read from the location twice on *nix, and from two different locations on Windows
|
||||||
*/
|
*/
|
||||||
read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Errno) {
|
read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Error) {
|
||||||
if offset < 0 {
|
if offset < 0 {
|
||||||
return 0, ERROR_NEGATIVE_OFFSET
|
return 0, ERROR_NEGATIVE_OFFSET
|
||||||
}
|
}
|
||||||
@@ -308,7 +308,7 @@ on Windows, write_at changes the position of the file cursor, on *nix, it does n
|
|||||||
|
|
||||||
will write to the location twice on *nix, and to two different locations on Windows
|
will write to the location twice on *nix, and to two different locations on Windows
|
||||||
*/
|
*/
|
||||||
write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Errno) {
|
write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Error) {
|
||||||
if offset < 0 {
|
if offset < 0 {
|
||||||
return 0, ERROR_NEGATIVE_OFFSET
|
return 0, ERROR_NEGATIVE_OFFSET
|
||||||
}
|
}
|
||||||
@@ -386,7 +386,7 @@ get_current_directory :: proc(allocator := context.allocator) -> string {
|
|||||||
return win32.utf16_to_utf8(dir_buf_wstr, allocator) or_else ""
|
return win32.utf16_to_utf8(dir_buf_wstr, allocator) or_else ""
|
||||||
}
|
}
|
||||||
|
|
||||||
set_current_directory :: proc(path: string) -> (err: Errno) {
|
set_current_directory :: proc(path: string) -> (err: Error) {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
wstr := win32.utf8_to_wstring(path, context.temp_allocator)
|
wstr := win32.utf8_to_wstring(path, context.temp_allocator)
|
||||||
|
|
||||||
@@ -402,7 +402,7 @@ set_current_directory :: proc(path: string) -> (err: Errno) {
|
|||||||
}
|
}
|
||||||
change_directory :: set_current_directory
|
change_directory :: set_current_directory
|
||||||
|
|
||||||
make_directory :: proc(path: string, mode: u32 = 0) -> (err: Errno) {
|
make_directory :: proc(path: string, mode: u32 = 0) -> (err: Error) {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
// Mode is unused on Windows, but is needed on *nix
|
// Mode is unused on Windows, but is needed on *nix
|
||||||
wpath := win32.utf8_to_wstring(path, context.temp_allocator)
|
wpath := win32.utf8_to_wstring(path, context.temp_allocator)
|
||||||
@@ -414,7 +414,7 @@ make_directory :: proc(path: string, mode: u32 = 0) -> (err: Errno) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
remove_directory :: proc(path: string) -> (err: Errno) {
|
remove_directory :: proc(path: string) -> (err: Error) {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
wpath := win32.utf8_to_wstring(path, context.temp_allocator)
|
wpath := win32.utf8_to_wstring(path, context.temp_allocator)
|
||||||
|
|
||||||
@@ -487,14 +487,14 @@ fix_long_path :: proc(path: string) -> string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
link :: proc(old_name, new_name: string) -> (err: Errno) {
|
link :: proc(old_name, new_name: string) -> (err: Error) {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
n := win32.utf8_to_wstring(fix_long_path(new_name))
|
n := win32.utf8_to_wstring(fix_long_path(new_name))
|
||||||
o := win32.utf8_to_wstring(fix_long_path(old_name))
|
o := win32.utf8_to_wstring(fix_long_path(old_name))
|
||||||
return Platform_Error(win32.CreateHardLinkW(n, o, nil))
|
return Platform_Error(win32.CreateHardLinkW(n, o, nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink :: proc(path: string) -> (err: Errno) {
|
unlink :: proc(path: string) -> (err: Error) {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
wpath := win32.utf8_to_wstring(path, context.temp_allocator)
|
wpath := win32.utf8_to_wstring(path, context.temp_allocator)
|
||||||
|
|
||||||
@@ -506,7 +506,7 @@ unlink :: proc(path: string) -> (err: Errno) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
rename :: proc(old_path, new_path: string) -> (err: Errno) {
|
rename :: proc(old_path, new_path: string) -> (err: Error) {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
from := win32.utf8_to_wstring(old_path, context.temp_allocator)
|
from := win32.utf8_to_wstring(old_path, context.temp_allocator)
|
||||||
to := win32.utf8_to_wstring(new_path, context.temp_allocator)
|
to := win32.utf8_to_wstring(new_path, context.temp_allocator)
|
||||||
@@ -518,7 +518,7 @@ rename :: proc(old_path, new_path: string) -> (err: Errno) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ftruncate :: proc(fd: Handle, length: i64) -> (err: Errno) {
|
ftruncate :: proc(fd: Handle, length: i64) -> (err: Error) {
|
||||||
curr_off := seek(fd, 0, 1) or_return
|
curr_off := seek(fd, 0, 1) or_return
|
||||||
defer seek(fd, curr_off, 0)
|
defer seek(fd, curr_off, 0)
|
||||||
_= seek(fd, length, 0) or_return
|
_= seek(fd, length, 0) or_return
|
||||||
@@ -529,14 +529,14 @@ ftruncate :: proc(fd: Handle, length: i64) -> (err: Errno) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
truncate :: proc(path: string, length: i64) -> (err: Errno) {
|
truncate :: proc(path: string, length: i64) -> (err: Error) {
|
||||||
fd := open(path, O_WRONLY|O_CREATE, 0o666) or_return
|
fd := open(path, O_WRONLY|O_CREATE, 0o666) or_return
|
||||||
defer close(fd)
|
defer close(fd)
|
||||||
return ftruncate(fd, length)
|
return ftruncate(fd, length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
remove :: proc(name: string) -> Errno {
|
remove :: proc(name: string) -> Error {
|
||||||
p := win32.utf8_to_wstring(fix_long_path(name))
|
p := win32.utf8_to_wstring(fix_long_path(name))
|
||||||
err, err1: win32.DWORD
|
err, err1: win32.DWORD
|
||||||
if !win32.DeleteFileW(p) {
|
if !win32.DeleteFileW(p) {
|
||||||
@@ -574,7 +574,7 @@ remove :: proc(name: string) -> Errno {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pipe :: proc() -> (r, w: Handle, err: Errno) {
|
pipe :: proc() -> (r, w: Handle, err: Error) {
|
||||||
sa: win32.SECURITY_ATTRIBUTES
|
sa: win32.SECURITY_ATTRIBUTES
|
||||||
sa.nLength = size_of(win32.SECURITY_ATTRIBUTES)
|
sa.nLength = size_of(win32.SECURITY_ATTRIBUTES)
|
||||||
sa.bInheritHandle = true
|
sa.bInheritHandle = true
|
||||||
|
|||||||
+8
-8
@@ -64,15 +64,15 @@ is_platform_error :: proc(ferr: Error) -> (err: i32, ok: bool) {
|
|||||||
return i32(v), i32(v) != 0
|
return i32(v), i32(v) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
write_string :: proc(fd: Handle, str: string) -> (int, Errno) {
|
write_string :: proc(fd: Handle, str: string) -> (int, Error) {
|
||||||
return write(fd, transmute([]byte)str)
|
return write(fd, transmute([]byte)str)
|
||||||
}
|
}
|
||||||
|
|
||||||
write_byte :: proc(fd: Handle, b: byte) -> (int, Errno) {
|
write_byte :: proc(fd: Handle, b: byte) -> (int, Error) {
|
||||||
return write(fd, []byte{b})
|
return write(fd, []byte{b})
|
||||||
}
|
}
|
||||||
|
|
||||||
write_rune :: proc(fd: Handle, r: rune) -> (int, Errno) {
|
write_rune :: proc(fd: Handle, r: rune) -> (int, Error) {
|
||||||
if r < utf8.RUNE_SELF {
|
if r < utf8.RUNE_SELF {
|
||||||
return write_byte(fd, byte(r))
|
return write_byte(fd, byte(r))
|
||||||
}
|
}
|
||||||
@@ -120,7 +120,7 @@ write_encoded_rune :: proc(f: Handle, r: rune) -> (n: int, err: Error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
read_at_least :: proc(fd: Handle, buf: []byte, min: int) -> (n: int, err: Errno) {
|
read_at_least :: proc(fd: Handle, buf: []byte, min: int) -> (n: int, err: Error) {
|
||||||
if len(buf) < min {
|
if len(buf) < min {
|
||||||
return 0, io.Error.Short_Buffer
|
return 0, io.Error.Short_Buffer
|
||||||
}
|
}
|
||||||
@@ -135,7 +135,7 @@ read_at_least :: proc(fd: Handle, buf: []byte, min: int) -> (n: int, err: Errno)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
read_full :: proc(fd: Handle, buf: []byte) -> (n: int, err: Errno) {
|
read_full :: proc(fd: Handle, buf: []byte) -> (n: int, err: Error) {
|
||||||
return read_at_least(fd, buf, len(buf))
|
return read_at_least(fd, buf, len(buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ read_entire_file_from_handle :: proc(fd: Handle, allocator := context.allocator,
|
|||||||
context.allocator = allocator
|
context.allocator = allocator
|
||||||
|
|
||||||
length: i64
|
length: i64
|
||||||
err: Errno
|
err: Error
|
||||||
if length, err = file_size(fd); err != nil {
|
if length, err = file_size(fd); err != nil {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
@@ -219,11 +219,11 @@ write_entire_file :: proc(name: string, data: []byte, truncate := true) -> (succ
|
|||||||
return write_err == nil
|
return write_err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
write_ptr :: proc(fd: Handle, data: rawptr, len: int) -> (int, Errno) {
|
write_ptr :: proc(fd: Handle, data: rawptr, len: int) -> (int, Error) {
|
||||||
return write(fd, ([^]byte)(data)[:len])
|
return write(fd, ([^]byte)(data)[:len])
|
||||||
}
|
}
|
||||||
|
|
||||||
read_ptr :: proc(fd: Handle, data: rawptr, len: int) -> (int, Errno) {
|
read_ptr :: proc(fd: Handle, data: rawptr, len: int) -> (int, Error) {
|
||||||
return read(fd, ([^]byte)(data)[:len])
|
return read(fd, ([^]byte)(data)[:len])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package os2
|
|||||||
import "core:sys/linux"
|
import "core:sys/linux"
|
||||||
|
|
||||||
@(rodata)
|
@(rodata)
|
||||||
_errno_strings : [linux.Errno]string = {
|
_errno_strings : [linux.Error]string = {
|
||||||
.NONE = "Success",
|
.NONE = "Success",
|
||||||
.EPERM = "Operation not permitted",
|
.EPERM = "Operation not permitted",
|
||||||
.ENOENT = "No such file or directory",
|
.ENOENT = "No such file or directory",
|
||||||
@@ -142,7 +142,7 @@ _errno_strings : [linux.Errno]string = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_get_platform_error :: proc(errno: linux.Errno) -> Error {
|
_get_platform_error :: proc(errno: linux.Error) -> Error {
|
||||||
#partial switch errno {
|
#partial switch errno {
|
||||||
case .NONE:
|
case .NONE:
|
||||||
return nil
|
return nil
|
||||||
@@ -158,8 +158,8 @@ _get_platform_error :: proc(errno: linux.Errno) -> Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_error_string :: proc(errno: i32) -> string {
|
_error_string :: proc(errno: i32) -> string {
|
||||||
if errno >= 0 && errno <= i32(max(linux.Errno)) {
|
if errno >= 0 && errno <= i32(max(linux.Error)) {
|
||||||
return _errno_strings[linux.Errno(errno)]
|
return _errno_strings[linux.Error(errno)]
|
||||||
}
|
}
|
||||||
return "Unknown Error"
|
return "Unknown Error"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ _mkdir_all :: proc(path: string, perm: int) -> Error {
|
|||||||
path_bytes[len(path)] = 0
|
path_bytes[len(path)] = 0
|
||||||
|
|
||||||
dfd: linux.Fd
|
dfd: linux.Fd
|
||||||
errno: linux.Errno
|
errno: linux.Error
|
||||||
if path_bytes[0] == '/' {
|
if path_bytes[0] == '/' {
|
||||||
dfd, errno = linux.open("/", _OPENDIR_FLAGS)
|
dfd, errno = linux.open("/", _OPENDIR_FLAGS)
|
||||||
path_bytes = path_bytes[1:]
|
path_bytes = path_bytes[1:]
|
||||||
|
|||||||
+74
-74
@@ -13,7 +13,7 @@ File_Time :: distinct u64
|
|||||||
|
|
||||||
INVALID_HANDLE :: ~Handle(0)
|
INVALID_HANDLE :: ~Handle(0)
|
||||||
|
|
||||||
_Platform_Error :: enum i32 {
|
_Platform_Error :: enum i32 {
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
EPERM = 1, /* Operation not permitted */
|
EPERM = 1, /* Operation not permitted */
|
||||||
ENOENT = 2, /* No such file or directory */
|
ENOENT = 2, /* No such file or directory */
|
||||||
@@ -149,7 +149,7 @@ _Platform_Error :: enum i32 {
|
|||||||
EOWNERDEAD = 105, /* Previous owner died */
|
EOWNERDEAD = 105, /* Previous owner died */
|
||||||
|
|
||||||
EQFUL = 106, /* Interface output queue is full */
|
EQFUL = 106, /* Interface output queue is full */
|
||||||
ELAS = 106, /* Must be equal largest errno */
|
ELAS = 106, /* Must be equal largest Error */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -644,7 +644,7 @@ get_last_error_string :: proc() -> string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
open :: proc(path: string, flags: int = O_RDWR, mode: int = 0) -> (handle: Handle, err: Errno) {
|
open :: proc(path: string, flags: int = O_RDWR, mode: int = 0) -> (handle: Handle, err: Error) {
|
||||||
isDir := is_dir_path(path)
|
isDir := is_dir_path(path)
|
||||||
flags := flags
|
flags := flags
|
||||||
if isDir {
|
if isDir {
|
||||||
@@ -678,11 +678,11 @@ open :: proc(path: string, flags: int = O_RDWR, mode: int = 0) -> (handle: Handl
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fchmod :: proc(fd: Handle, mode: u16) -> Errno {
|
fchmod :: proc(fd: Handle, mode: u16) -> Error {
|
||||||
return cast(Platform_Error)_unix_fchmod(fd, mode)
|
return cast(Platform_Error)_unix_fchmod(fd, mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
close :: proc(fd: Handle) -> Errno {
|
close :: proc(fd: Handle) -> Error {
|
||||||
return cast(Platform_Error)_unix_close(fd)
|
return cast(Platform_Error)_unix_close(fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -696,7 +696,7 @@ close :: proc(fd: Handle) -> Errno {
|
|||||||
@(private)
|
@(private)
|
||||||
MAX_RW :: 1 << 30
|
MAX_RW :: 1 << 30
|
||||||
|
|
||||||
write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
write :: proc(fd: Handle, data: []byte) -> (int, Error) {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
@@ -705,12 +705,12 @@ write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
|||||||
|
|
||||||
bytes_written := _unix_write(fd, raw_data(data), to_write)
|
bytes_written := _unix_write(fd, raw_data(data), to_write)
|
||||||
if bytes_written < 0 {
|
if bytes_written < 0 {
|
||||||
return -1, Errno(get_last_error())
|
return -1, Error(get_last_error())
|
||||||
}
|
}
|
||||||
return bytes_written, nil
|
return bytes_written, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
read :: proc(fd: Handle, data: []u8) -> (int, Errno) {
|
read :: proc(fd: Handle, data: []u8) -> (int, Error) {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
@@ -719,12 +719,12 @@ read :: proc(fd: Handle, data: []u8) -> (int, Errno) {
|
|||||||
|
|
||||||
bytes_read := _unix_read(fd, raw_data(data), to_read)
|
bytes_read := _unix_read(fd, raw_data(data), to_read)
|
||||||
if bytes_read < 0 {
|
if bytes_read < 0 {
|
||||||
return -1, Errno(get_last_error())
|
return -1, Error(get_last_error())
|
||||||
}
|
}
|
||||||
return bytes_read, nil
|
return bytes_read, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Error) {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
@@ -733,12 +733,12 @@ read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
|||||||
|
|
||||||
bytes_read := _unix_pread(fd, raw_data(data), to_read, offset)
|
bytes_read := _unix_pread(fd, raw_data(data), to_read, offset)
|
||||||
if bytes_read < 0 {
|
if bytes_read < 0 {
|
||||||
return -1, Errno(get_last_error())
|
return -1, Error(get_last_error())
|
||||||
}
|
}
|
||||||
return bytes_read, nil
|
return bytes_read, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Error) {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
@@ -747,12 +747,12 @@ write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
|||||||
|
|
||||||
bytes_written := _unix_pwrite(fd, raw_data(data), to_write, offset)
|
bytes_written := _unix_pwrite(fd, raw_data(data), to_write, offset)
|
||||||
if bytes_written < 0 {
|
if bytes_written < 0 {
|
||||||
return -1, Errno(get_last_error())
|
return -1, Error(get_last_error())
|
||||||
}
|
}
|
||||||
return bytes_written, nil
|
return bytes_written, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Error) {
|
||||||
assert(fd != -1)
|
assert(fd != -1)
|
||||||
|
|
||||||
final_offset := i64(_unix_lseek(fd, int(offset), c.int(whence)))
|
final_offset := i64(_unix_lseek(fd, int(offset), c.int(whence)))
|
||||||
@@ -762,7 +762,7 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
|||||||
return final_offset, nil
|
return final_offset, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
file_size :: proc(fd: Handle) -> (i64, Errno) {
|
file_size :: proc(fd: Handle) -> (i64, Error) {
|
||||||
prev, _ := seek(fd, 0, SEEK_CUR)
|
prev, _ := seek(fd, 0, SEEK_CUR)
|
||||||
size, err := seek(fd, 0, SEEK_END)
|
size, err := seek(fd, 0, SEEK_END)
|
||||||
seek(fd, prev, SEEK_SET)
|
seek(fd, prev, SEEK_SET)
|
||||||
@@ -776,13 +776,13 @@ stdin: Handle = 0 // get_std_handle(win32.STD_INPUT_HANDLE);
|
|||||||
stdout: Handle = 1 // get_std_handle(win32.STD_OUTPUT_HANDLE);
|
stdout: Handle = 1 // get_std_handle(win32.STD_OUTPUT_HANDLE);
|
||||||
stderr: Handle = 2 // get_std_handle(win32.STD_ERROR_HANDLE);
|
stderr: Handle = 2 // get_std_handle(win32.STD_ERROR_HANDLE);
|
||||||
|
|
||||||
last_write_time :: proc(fd: Handle) -> (time: File_Time, err: Errno) {
|
last_write_time :: proc(fd: Handle) -> (time: File_Time, err: Error) {
|
||||||
s := _fstat(fd) or_return
|
s := _fstat(fd) or_return
|
||||||
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
||||||
return File_Time(modified), nil
|
return File_Time(modified), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
last_write_time_by_name :: proc(name: string) -> (time: File_Time, err: Errno) {
|
last_write_time_by_name :: proc(name: string) -> (time: File_Time, err: Error) {
|
||||||
s := _stat(name) or_return
|
s := _stat(name) or_return
|
||||||
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
||||||
return File_Time(modified), nil
|
return File_Time(modified), nil
|
||||||
@@ -803,7 +803,7 @@ is_file_handle :: proc(fd: Handle) -> bool {
|
|||||||
|
|
||||||
is_file_path :: proc(path: string, follow_links: bool = true) -> bool {
|
is_file_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||||
s: OS_Stat
|
s: OS_Stat
|
||||||
err: Errno
|
err: Error
|
||||||
if follow_links {
|
if follow_links {
|
||||||
s, err = _stat(path)
|
s, err = _stat(path)
|
||||||
} else {
|
} else {
|
||||||
@@ -826,7 +826,7 @@ is_dir_handle :: proc(fd: Handle) -> bool {
|
|||||||
|
|
||||||
is_dir_path :: proc(path: string, follow_links: bool = true) -> bool {
|
is_dir_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||||
s: OS_Stat
|
s: OS_Stat
|
||||||
err: Errno
|
err: Error
|
||||||
if follow_links {
|
if follow_links {
|
||||||
s, err = _stat(path)
|
s, err = _stat(path)
|
||||||
} else {
|
} else {
|
||||||
@@ -855,66 +855,66 @@ rename :: proc(old: string, new: string) -> bool {
|
|||||||
return _unix_rename(old_cstr, new_cstr) != -1
|
return _unix_rename(old_cstr, new_cstr) != -1
|
||||||
}
|
}
|
||||||
|
|
||||||
remove :: proc(path: string) -> Errno {
|
remove :: proc(path: string) -> Error {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
res := _unix_remove(path_cstr)
|
res := _unix_remove(path_cstr)
|
||||||
if res == -1 {
|
if res == -1 {
|
||||||
return Errno(get_last_error())
|
return Error(get_last_error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@private
|
@private
|
||||||
_stat :: proc(path: string) -> (OS_Stat, Errno) {
|
_stat :: proc(path: string) -> (OS_Stat, Error) {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
|
|
||||||
s: OS_Stat
|
s: OS_Stat
|
||||||
result := _unix_stat(cstr, &s)
|
result := _unix_stat(cstr, &s)
|
||||||
if result == -1 {
|
if result == -1 {
|
||||||
return s, Errno(get_last_error())
|
return s, Error(get_last_error())
|
||||||
}
|
}
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@private
|
@private
|
||||||
_lstat :: proc(path: string) -> (OS_Stat, Errno) {
|
_lstat :: proc(path: string) -> (OS_Stat, Error) {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
|
|
||||||
s: OS_Stat
|
s: OS_Stat
|
||||||
result := _unix_lstat(cstr, &s)
|
result := _unix_lstat(cstr, &s)
|
||||||
if result == -1 {
|
if result == -1 {
|
||||||
return s, Errno(get_last_error())
|
return s, Error(get_last_error())
|
||||||
}
|
}
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@private
|
@private
|
||||||
_fstat :: proc(fd: Handle) -> (OS_Stat, Errno) {
|
_fstat :: proc(fd: Handle) -> (OS_Stat, Error) {
|
||||||
s: OS_Stat
|
s: OS_Stat
|
||||||
result := _unix_fstat(fd, &s)
|
result := _unix_fstat(fd, &s)
|
||||||
if result == -1 {
|
if result == -1 {
|
||||||
return s, Errno(get_last_error())
|
return s, Error(get_last_error())
|
||||||
}
|
}
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@private
|
@private
|
||||||
_fdopendir :: proc(fd: Handle) -> (Dir, Errno) {
|
_fdopendir :: proc(fd: Handle) -> (Dir, Error) {
|
||||||
dirp := _unix_fdopendir(fd)
|
dirp := _unix_fdopendir(fd)
|
||||||
if dirp == cast(Dir)nil {
|
if dirp == cast(Dir)nil {
|
||||||
return nil, Errno(get_last_error())
|
return nil, Error(get_last_error())
|
||||||
}
|
}
|
||||||
return dirp, nil
|
return dirp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@private
|
@private
|
||||||
_closedir :: proc(dirp: Dir) -> Errno {
|
_closedir :: proc(dirp: Dir) -> Error {
|
||||||
rc := _unix_closedir(dirp)
|
rc := _unix_closedir(dirp)
|
||||||
if rc != 0 {
|
if rc != 0 {
|
||||||
return Errno(get_last_error())
|
return Error(get_last_error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -925,12 +925,12 @@ _rewinddir :: proc(dirp: Dir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@private
|
@private
|
||||||
_readdir :: proc(dirp: Dir) -> (entry: Dirent, err: Errno, end_of_stream: bool) {
|
_readdir :: proc(dirp: Dir) -> (entry: Dirent, err: Error, end_of_stream: bool) {
|
||||||
result: ^Dirent
|
result: ^Dirent
|
||||||
rc := _unix_readdir_r(dirp, &entry, &result)
|
rc := _unix_readdir_r(dirp, &entry, &result)
|
||||||
|
|
||||||
if rc != 0 {
|
if rc != 0 {
|
||||||
err = Errno(get_last_error())
|
err = Error(get_last_error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -944,7 +944,7 @@ _readdir :: proc(dirp: Dir) -> (entry: Dirent, err: Errno, end_of_stream: bool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
@private
|
@private
|
||||||
_readlink :: proc(path: string) -> (string, Errno) {
|
_readlink :: proc(path: string) -> (string, Error) {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == context.allocator)
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == context.allocator)
|
||||||
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
|
|
||||||
@@ -954,7 +954,7 @@ _readlink :: proc(path: string) -> (string, Errno) {
|
|||||||
rc := _unix_readlink(path_cstr, &(buf[0]), bufsz)
|
rc := _unix_readlink(path_cstr, &(buf[0]), bufsz)
|
||||||
if rc == -1 {
|
if rc == -1 {
|
||||||
delete(buf)
|
delete(buf)
|
||||||
return "", Errno(get_last_error())
|
return "", Error(get_last_error())
|
||||||
} else if rc == int(bufsz) {
|
} else if rc == int(bufsz) {
|
||||||
// NOTE(laleksic, 2021-01-21): Any cleaner way to resize the slice?
|
// NOTE(laleksic, 2021-01-21): Any cleaner way to resize the slice?
|
||||||
bufsz *= 2
|
bufsz *= 2
|
||||||
@@ -966,13 +966,13 @@ _readlink :: proc(path: string) -> (string, Errno) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
absolute_path_from_handle :: proc(fd: Handle) -> (path: string, err: Errno) {
|
absolute_path_from_handle :: proc(fd: Handle) -> (path: string, err: Error) {
|
||||||
buf: [DARWIN_MAXPATHLEN]byte
|
buf: [DARWIN_MAXPATHLEN]byte
|
||||||
_ = fcntl(int(fd), F_GETPATH, int(uintptr(&buf[0]))) or_return
|
_ = fcntl(int(fd), F_GETPATH, int(uintptr(&buf[0]))) or_return
|
||||||
return strings.clone_from_cstring(cstring(&buf[0]))
|
return strings.clone_from_cstring(cstring(&buf[0]))
|
||||||
}
|
}
|
||||||
|
|
||||||
absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Errno) {
|
absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Error) {
|
||||||
rel := rel
|
rel := rel
|
||||||
if rel == "" {
|
if rel == "" {
|
||||||
rel = "."
|
rel = "."
|
||||||
@@ -983,7 +983,7 @@ absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Errno) {
|
|||||||
|
|
||||||
path_ptr := _unix_realpath(rel_cstr, nil)
|
path_ptr := _unix_realpath(rel_cstr, nil)
|
||||||
if path_ptr == nil {
|
if path_ptr == nil {
|
||||||
return "", Errno(get_last_error())
|
return "", Error(get_last_error())
|
||||||
}
|
}
|
||||||
defer _unix_free(path_ptr)
|
defer _unix_free(path_ptr)
|
||||||
|
|
||||||
@@ -999,7 +999,7 @@ access :: proc(path: string, mask: int) -> bool {
|
|||||||
return _unix_access(cstr, c.int(mask)) == 0
|
return _unix_access(cstr, c.int(mask)) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
flush :: proc(fd: Handle) -> Errno {
|
flush :: proc(fd: Handle) -> Error {
|
||||||
return cast(Platform_Error)_unix_fsync(fd)
|
return cast(Platform_Error)_unix_fsync(fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1018,23 +1018,23 @@ get_env :: proc(key: string, allocator := context.allocator) -> (value: string)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
set_env :: proc(key, value: string) -> Errno {
|
set_env :: proc(key, value: string) -> Error {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
key_cstring := strings.clone_to_cstring(key, context.temp_allocator)
|
key_cstring := strings.clone_to_cstring(key, context.temp_allocator)
|
||||||
value_cstring := strings.clone_to_cstring(value, context.temp_allocator)
|
value_cstring := strings.clone_to_cstring(value, context.temp_allocator)
|
||||||
res := _unix_setenv(key_cstring, value_cstring, 1)
|
res := _unix_setenv(key_cstring, value_cstring, 1)
|
||||||
if res < 0 {
|
if res < 0 {
|
||||||
return Errno(get_last_error())
|
return Error(get_last_error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
unset_env :: proc(key: string) -> Errno {
|
unset_env :: proc(key: string) -> Error {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
s := strings.clone_to_cstring(key, context.temp_allocator)
|
s := strings.clone_to_cstring(key, context.temp_allocator)
|
||||||
res := _unix_unsetenv(s)
|
res := _unix_unsetenv(s)
|
||||||
if res < 0 {
|
if res < 0 {
|
||||||
return Errno(get_last_error())
|
return Error(get_last_error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1047,7 +1047,7 @@ get_current_directory :: proc() -> string {
|
|||||||
if cwd != nil {
|
if cwd != nil {
|
||||||
return string(cwd)
|
return string(cwd)
|
||||||
}
|
}
|
||||||
if Errno(get_last_error()) != ERANGE {
|
if Error(get_last_error()) != ERANGE {
|
||||||
delete(buf)
|
delete(buf)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -1056,22 +1056,22 @@ get_current_directory :: proc() -> string {
|
|||||||
unreachable()
|
unreachable()
|
||||||
}
|
}
|
||||||
|
|
||||||
set_current_directory :: proc(path: string) -> (err: Errno) {
|
set_current_directory :: proc(path: string) -> (err: Error) {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
res := _unix_chdir(cstr)
|
res := _unix_chdir(cstr)
|
||||||
if res == -1 {
|
if res == -1 {
|
||||||
return Errno(get_last_error())
|
return Error(get_last_error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
make_directory :: proc(path: string, mode: u16 = 0o775) -> Errno {
|
make_directory :: proc(path: string, mode: u16 = 0o775) -> Error {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
res := _unix_mkdir(path_cstr, mode)
|
res := _unix_mkdir(path_cstr, mode)
|
||||||
if res == -1 {
|
if res == -1 {
|
||||||
return Errno(get_last_error())
|
return Error(get_last_error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1145,106 +1145,106 @@ _alloc_command_line_arguments :: proc() -> []string {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
socket :: proc(domain: int, type: int, protocol: int) -> (Socket, Errno) {
|
socket :: proc(domain: int, type: int, protocol: int) -> (Socket, Error) {
|
||||||
result := _unix_socket(domain, type, protocol)
|
result := _unix_socket(domain, type, protocol)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return 0, Errno(get_last_error())
|
return 0, Error(get_last_error())
|
||||||
}
|
}
|
||||||
return Socket(result), nil
|
return Socket(result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
connect :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Errno) {
|
connect :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Error) {
|
||||||
result := _unix_connect(int(sd), addr, len)
|
result := _unix_connect(int(sd), addr, len)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return Errno(get_last_error())
|
return Error(get_last_error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
bind :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Errno) {
|
bind :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Error) {
|
||||||
result := _unix_bind(int(sd), addr, len)
|
result := _unix_bind(int(sd), addr, len)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return Errno(get_last_error())
|
return Error(get_last_error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
accept :: proc(sd: Socket, addr: ^SOCKADDR, len: rawptr) -> (Socket, Errno) {
|
accept :: proc(sd: Socket, addr: ^SOCKADDR, len: rawptr) -> (Socket, Error) {
|
||||||
result := _unix_accept(int(sd), rawptr(addr), len)
|
result := _unix_accept(int(sd), rawptr(addr), len)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return 0, Errno(get_last_error())
|
return 0, Error(get_last_error())
|
||||||
}
|
}
|
||||||
return Socket(result), nil
|
return Socket(result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
listen :: proc(sd: Socket, backlog: int) -> (Errno) {
|
listen :: proc(sd: Socket, backlog: int) -> (Error) {
|
||||||
result := _unix_listen(int(sd), backlog)
|
result := _unix_listen(int(sd), backlog)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return Errno(get_last_error())
|
return Error(get_last_error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
setsockopt :: proc(sd: Socket, level: int, optname: int, optval: rawptr, optlen: socklen_t) -> (Errno) {
|
setsockopt :: proc(sd: Socket, level: int, optname: int, optval: rawptr, optlen: socklen_t) -> (Error) {
|
||||||
result := _unix_setsockopt(int(sd), level, optname, optval, optlen)
|
result := _unix_setsockopt(int(sd), level, optname, optval, optlen)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return Errno(get_last_error())
|
return Error(get_last_error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
getsockopt :: proc(sd: Socket, level: int, optname: int, optval: rawptr, optlen: socklen_t) -> Errno {
|
getsockopt :: proc(sd: Socket, level: int, optname: int, optval: rawptr, optlen: socklen_t) -> Error {
|
||||||
result := _unix_getsockopt(int(sd), level, optname, optval, optlen)
|
result := _unix_getsockopt(int(sd), level, optname, optval, optlen)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return Errno(get_last_error())
|
return Error(get_last_error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
recvfrom :: proc(sd: Socket, data: []byte, flags: int, addr: ^SOCKADDR, addr_size: ^socklen_t) -> (u32, Errno) {
|
recvfrom :: proc(sd: Socket, data: []byte, flags: int, addr: ^SOCKADDR, addr_size: ^socklen_t) -> (u32, Error) {
|
||||||
result := _unix_recvfrom(int(sd), raw_data(data), len(data), flags, addr, addr_size)
|
result := _unix_recvfrom(int(sd), raw_data(data), len(data), flags, addr, addr_size)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return 0, Errno(get_last_error())
|
return 0, Error(get_last_error())
|
||||||
}
|
}
|
||||||
return u32(result), nil
|
return u32(result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
recv :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Errno) {
|
recv :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Error) {
|
||||||
result := _unix_recv(int(sd), raw_data(data), len(data), flags)
|
result := _unix_recv(int(sd), raw_data(data), len(data), flags)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return 0, Errno(get_last_error())
|
return 0, Error(get_last_error())
|
||||||
}
|
}
|
||||||
return u32(result), nil
|
return u32(result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
sendto :: proc(sd: Socket, data: []u8, flags: int, addr: ^SOCKADDR, addrlen: socklen_t) -> (u32, Errno) {
|
sendto :: proc(sd: Socket, data: []u8, flags: int, addr: ^SOCKADDR, addrlen: socklen_t) -> (u32, Error) {
|
||||||
result := _unix_sendto(int(sd), raw_data(data), len(data), flags, addr, addrlen)
|
result := _unix_sendto(int(sd), raw_data(data), len(data), flags, addr, addrlen)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return 0, Errno(get_last_error())
|
return 0, Error(get_last_error())
|
||||||
}
|
}
|
||||||
return u32(result), nil
|
return u32(result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
send :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Errno) {
|
send :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Error) {
|
||||||
result := _unix_send(int(sd), raw_data(data), len(data), 0)
|
result := _unix_send(int(sd), raw_data(data), len(data), 0)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return 0, Errno(get_last_error())
|
return 0, Error(get_last_error())
|
||||||
}
|
}
|
||||||
return u32(result), nil
|
return u32(result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
shutdown :: proc(sd: Socket, how: int) -> (Errno) {
|
shutdown :: proc(sd: Socket, how: int) -> (Error) {
|
||||||
result := _unix_shutdown(int(sd), how)
|
result := _unix_shutdown(int(sd), how)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return Errno(get_last_error())
|
return Error(get_last_error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fcntl :: proc(fd: int, cmd: int, arg: int) -> (int, Errno) {
|
fcntl :: proc(fd: int, cmd: int, arg: int) -> (int, Error) {
|
||||||
result := _unix__fcntl(Handle(fd), c.int(cmd), uintptr(arg))
|
result := _unix__fcntl(Handle(fd), c.int(cmd), uintptr(arg))
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return 0, Errno(get_last_error())
|
return 0, Error(get_last_error())
|
||||||
}
|
}
|
||||||
return int(result), nil
|
return int(result), nil
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-13
@@ -5,7 +5,7 @@ import "core:sys/es"
|
|||||||
Handle :: distinct int
|
Handle :: distinct int
|
||||||
_Platform_Error :: enum i32 {NONE}
|
_Platform_Error :: enum i32 {NONE}
|
||||||
|
|
||||||
// ERROR_NONE :: Errno(es.SUCCESS)
|
// ERROR_NONE :: Error(es.SUCCESS)
|
||||||
|
|
||||||
O_RDONLY :: 0x1
|
O_RDONLY :: 0x1
|
||||||
O_WRONLY :: 0x2
|
O_WRONLY :: 0x2
|
||||||
@@ -30,26 +30,26 @@ heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr {
|
|||||||
return es.HeapReallocate(ptr, new_size, false)
|
return es.HeapReallocate(ptr, new_size, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0) -> (Handle, Errno) {
|
open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0) -> (Handle, Error) {
|
||||||
return (Handle) (0), (Errno) (1)
|
return (Handle) (0), (Error) (1)
|
||||||
}
|
}
|
||||||
|
|
||||||
close :: proc(fd: Handle) -> Errno {
|
close :: proc(fd: Handle) -> Error {
|
||||||
return (Errno) (1)
|
return (Error) (1)
|
||||||
}
|
}
|
||||||
|
|
||||||
file_size :: proc(fd: Handle) -> (i64, Errno) {
|
file_size :: proc(fd: Handle) -> (i64, Error) {
|
||||||
return (i64) (0), (Errno) (1)
|
return (i64) (0), (Error) (1)
|
||||||
}
|
}
|
||||||
|
|
||||||
read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
read :: proc(fd: Handle, data: []byte) -> (int, Error) {
|
||||||
return (int) (0), (Errno) (1)
|
return (int) (0), (Error) (1)
|
||||||
}
|
}
|
||||||
|
|
||||||
write :: proc(fd: Handle, data: []u8) -> (int, Errno) {
|
write :: proc(fd: Handle, data: []u8) -> (int, Error) {
|
||||||
return (int) (0), (Errno) (1)
|
return (int) (0), (Error) (1)
|
||||||
}
|
}
|
||||||
|
|
||||||
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Error) {
|
||||||
return (i64) (0), (Errno) (1)
|
return (i64) (0), (Error) (1)
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-26
@@ -7,38 +7,38 @@ is_path_separator :: proc(c: byte) -> bool {
|
|||||||
return c == '/' || c == '\\'
|
return c == '/' || c == '\\'
|
||||||
}
|
}
|
||||||
|
|
||||||
open :: proc(path: string, mode: int = O_RDONLY, perm: int = 0) -> (Handle, Errno) {
|
open :: proc(path: string, mode: int = O_RDONLY, perm: int = 0) -> (Handle, Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
close :: proc(fd: Handle) -> Errno {
|
close :: proc(fd: Handle) -> Error {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
flush :: proc(fd: Handle) -> (err: Errno) {
|
flush :: proc(fd: Handle) -> (err: Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
write :: proc(fd: Handle, data: []byte) -> (int, Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private="file")
|
@(private="file")
|
||||||
read_console :: proc(handle: Handle, b: []byte) -> (n: int, err: Errno) {
|
read_console :: proc(handle: Handle, b: []byte) -> (n: int, err: Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
read :: proc(fd: Handle, data: []byte) -> (int, Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
file_size :: proc(fd: Handle) -> (i64, Errno) {
|
file_size :: proc(fd: Handle) -> (i64, Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,18 +47,18 @@ file_size :: proc(fd: Handle) -> (i64, Errno) {
|
|||||||
MAX_RW :: 1<<30
|
MAX_RW :: 1<<30
|
||||||
|
|
||||||
@(private)
|
@(private)
|
||||||
pread :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
pread :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
@(private)
|
@(private)
|
||||||
pwrite :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
pwrite :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Errno) {
|
read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Errno) {
|
write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,22 +90,22 @@ get_current_directory :: proc(allocator := context.allocator) -> string {
|
|||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
set_current_directory :: proc(path: string) -> (err: Errno) {
|
set_current_directory :: proc(path: string) -> (err: Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
change_directory :: proc(path: string) -> (err: Errno) {
|
change_directory :: proc(path: string) -> (err: Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
make_directory :: proc(path: string, mode: u32 = 0) -> (err: Errno) {
|
make_directory :: proc(path: string, mode: u32 = 0) -> (err: Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
remove_directory :: proc(path: string) -> (err: Errno) {
|
remove_directory :: proc(path: string) -> (err: Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,40 +122,40 @@ fix_long_path :: proc(path: string) -> string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
link :: proc(old_name, new_name: string) -> (err: Errno) {
|
link :: proc(old_name, new_name: string) -> (err: Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink :: proc(path: string) -> (err: Errno) {
|
unlink :: proc(path: string) -> (err: Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
rename :: proc(old_path, new_path: string) -> (err: Errno) {
|
rename :: proc(old_path, new_path: string) -> (err: Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ftruncate :: proc(fd: Handle, length: i64) -> (err: Errno) {
|
ftruncate :: proc(fd: Handle, length: i64) -> (err: Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
truncate :: proc(path: string, length: i64) -> (err: Errno) {
|
truncate :: proc(path: string, length: i64) -> (err: Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
remove :: proc(name: string) -> Errno {
|
remove :: proc(name: string) -> Error {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pipe :: proc() -> (r, w: Handle, err: Errno) {
|
pipe :: proc() -> (r, w: Handle, err: Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []File_Info, err: Errno) {
|
read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []File_Info, err: Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,11 +253,11 @@ args := _alloc_command_line_arguments()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
last_write_time :: proc(fd: Handle) -> (File_Time, Errno) {
|
last_write_time :: proc(fd: Handle) -> (File_Time, Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
last_write_time_by_name :: proc(name: string) -> (File_Time, Errno) {
|
last_write_time_by_name :: proc(name: string) -> (File_Time, Error) {
|
||||||
unimplemented("core:os procedure not supported on JS target")
|
unimplemented("core:os procedure not supported on JS target")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+54
-54
@@ -512,7 +512,7 @@ is_path_separator :: proc(r: rune) -> bool {
|
|||||||
|
|
||||||
// determine errno from syscall return value
|
// determine errno from syscall return value
|
||||||
@private
|
@private
|
||||||
_get_errno :: proc(res: int) -> Errno {
|
_get_errno :: proc(res: int) -> Error {
|
||||||
if res < 0 && res > -4096 {
|
if res < 0 && res > -4096 {
|
||||||
return Platform_Error(-res)
|
return Platform_Error(-res)
|
||||||
}
|
}
|
||||||
@@ -535,7 +535,7 @@ get_last_error :: proc "contextless" () -> Error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
personality :: proc(persona: u64) -> (Errno) {
|
personality :: proc(persona: u64) -> (Error) {
|
||||||
res := unix.sys_personality(persona)
|
res := unix.sys_personality(persona)
|
||||||
if res == -1 {
|
if res == -1 {
|
||||||
return _get_errno(res)
|
return _get_errno(res)
|
||||||
@@ -543,7 +543,7 @@ personality :: proc(persona: u64) -> (Errno) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fork :: proc() -> (Pid, Errno) {
|
fork :: proc() -> (Pid, Error) {
|
||||||
pid := unix.sys_fork()
|
pid := unix.sys_fork()
|
||||||
if pid == -1 {
|
if pid == -1 {
|
||||||
return -1, _get_errno(pid)
|
return -1, _get_errno(pid)
|
||||||
@@ -551,7 +551,7 @@ fork :: proc() -> (Pid, Errno) {
|
|||||||
return Pid(pid), nil
|
return Pid(pid), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
execvp :: proc(path: string, args: []string) -> Errno {
|
execvp :: proc(path: string, args: []string) -> Error {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
|
|
||||||
@@ -562,11 +562,11 @@ execvp :: proc(path: string, args: []string) -> Errno {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_unix_execvp(path_cstr, raw_data(args_cstrs))
|
_unix_execvp(path_cstr, raw_data(args_cstrs))
|
||||||
return Errno(get_last_error())
|
return Error(get_last_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0o000) -> (Handle, Errno) {
|
open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0o000) -> (Handle, Error) {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
handle := unix.sys_open(cstr, flags, uint(mode))
|
handle := unix.sys_open(cstr, flags, uint(mode))
|
||||||
@@ -576,7 +576,7 @@ open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0o000) -> (Handle,
|
|||||||
return Handle(handle), nil
|
return Handle(handle), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
close :: proc(fd: Handle) -> Errno {
|
close :: proc(fd: Handle) -> Error {
|
||||||
return _get_errno(unix.sys_close(int(fd)))
|
return _get_errno(unix.sys_close(int(fd)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -589,7 +589,7 @@ close :: proc(fd: Handle) -> Errno {
|
|||||||
@(private)
|
@(private)
|
||||||
MAX_RW :: 1 << 30
|
MAX_RW :: 1 << 30
|
||||||
|
|
||||||
read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
read :: proc(fd: Handle, data: []byte) -> (int, Error) {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
@@ -603,7 +603,7 @@ read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
|||||||
return bytes_read, nil
|
return bytes_read, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
write :: proc(fd: Handle, data: []byte) -> (int, Error) {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
@@ -617,7 +617,7 @@ write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
|||||||
return bytes_written, nil
|
return bytes_written, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Error) {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
@@ -631,7 +631,7 @@ read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
|||||||
return bytes_read, nil
|
return bytes_read, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Error) {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
@@ -645,7 +645,7 @@ write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
|
|||||||
return bytes_written, nil
|
return bytes_written, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Error) {
|
||||||
res := unix.sys_lseek(int(fd), offset, whence)
|
res := unix.sys_lseek(int(fd), offset, whence)
|
||||||
if res < 0 {
|
if res < 0 {
|
||||||
return -1, _get_errno(int(res))
|
return -1, _get_errno(int(res))
|
||||||
@@ -653,7 +653,7 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
|||||||
return i64(res), nil
|
return i64(res), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
file_size :: proc(fd: Handle) -> (i64, Errno) {
|
file_size :: proc(fd: Handle) -> (i64, Error) {
|
||||||
// deliberately uninitialized; the syscall fills this buffer for us
|
// deliberately uninitialized; the syscall fills this buffer for us
|
||||||
s: OS_Stat = ---
|
s: OS_Stat = ---
|
||||||
result := unix.sys_fstat(int(fd), rawptr(&s))
|
result := unix.sys_fstat(int(fd), rawptr(&s))
|
||||||
@@ -663,26 +663,26 @@ file_size :: proc(fd: Handle) -> (i64, Errno) {
|
|||||||
return max(s.size, 0), nil
|
return max(s.size, 0), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
rename :: proc(old_path, new_path: string) -> Errno {
|
rename :: proc(old_path, new_path: string) -> Error {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
old_path_cstr := strings.clone_to_cstring(old_path, context.temp_allocator)
|
old_path_cstr := strings.clone_to_cstring(old_path, context.temp_allocator)
|
||||||
new_path_cstr := strings.clone_to_cstring(new_path, context.temp_allocator)
|
new_path_cstr := strings.clone_to_cstring(new_path, context.temp_allocator)
|
||||||
return _get_errno(unix.sys_rename(old_path_cstr, new_path_cstr))
|
return _get_errno(unix.sys_rename(old_path_cstr, new_path_cstr))
|
||||||
}
|
}
|
||||||
|
|
||||||
remove :: proc(path: string) -> Errno {
|
remove :: proc(path: string) -> Error {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
return _get_errno(unix.sys_unlink(path_cstr))
|
return _get_errno(unix.sys_unlink(path_cstr))
|
||||||
}
|
}
|
||||||
|
|
||||||
make_directory :: proc(path: string, mode: u32 = 0o775) -> Errno {
|
make_directory :: proc(path: string, mode: u32 = 0o775) -> Error {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
return _get_errno(unix.sys_mkdir(path_cstr, uint(mode)))
|
return _get_errno(unix.sys_mkdir(path_cstr, uint(mode)))
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_directory :: proc(path: string) -> Errno {
|
remove_directory :: proc(path: string) -> Error {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
return _get_errno(unix.sys_rmdir(path_cstr))
|
return _get_errno(unix.sys_rmdir(path_cstr))
|
||||||
@@ -698,7 +698,7 @@ is_file_handle :: proc(fd: Handle) -> bool {
|
|||||||
|
|
||||||
is_file_path :: proc(path: string, follow_links: bool = true) -> bool {
|
is_file_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||||
s: OS_Stat
|
s: OS_Stat
|
||||||
err: Errno
|
err: Error
|
||||||
if follow_links {
|
if follow_links {
|
||||||
s, err = _stat(path)
|
s, err = _stat(path)
|
||||||
} else {
|
} else {
|
||||||
@@ -721,7 +721,7 @@ is_dir_handle :: proc(fd: Handle) -> bool {
|
|||||||
|
|
||||||
is_dir_path :: proc(path: string, follow_links: bool = true) -> bool {
|
is_dir_path :: proc(path: string, follow_links: bool = true) -> bool {
|
||||||
s: OS_Stat
|
s: OS_Stat
|
||||||
err: Errno
|
err: Error
|
||||||
if follow_links {
|
if follow_links {
|
||||||
s, err = _stat(path)
|
s, err = _stat(path)
|
||||||
} else {
|
} else {
|
||||||
@@ -753,20 +753,20 @@ stderr: Handle = 2
|
|||||||
last_write_time :: proc(fd: Handle) -> File_Time {}
|
last_write_time :: proc(fd: Handle) -> File_Time {}
|
||||||
last_write_time_by_name :: proc(name: string) -> File_Time {}
|
last_write_time_by_name :: proc(name: string) -> File_Time {}
|
||||||
*/
|
*/
|
||||||
last_write_time :: proc(fd: Handle) -> (time: File_Time, err: Errno) {
|
last_write_time :: proc(fd: Handle) -> (time: File_Time, err: Error) {
|
||||||
s := _fstat(fd) or_return
|
s := _fstat(fd) or_return
|
||||||
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
||||||
return File_Time(modified), nil
|
return File_Time(modified), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
last_write_time_by_name :: proc(name: string) -> (time: File_Time, err: Errno) {
|
last_write_time_by_name :: proc(name: string) -> (time: File_Time, err: Error) {
|
||||||
s := _stat(name) or_return
|
s := _stat(name) or_return
|
||||||
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
modified := s.modified.seconds * 1_000_000_000 + s.modified.nanoseconds
|
||||||
return File_Time(modified), nil
|
return File_Time(modified), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@private
|
@private
|
||||||
_stat :: proc(path: string) -> (OS_Stat, Errno) {
|
_stat :: proc(path: string) -> (OS_Stat, Error) {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
|
|
||||||
@@ -780,7 +780,7 @@ _stat :: proc(path: string) -> (OS_Stat, Errno) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@private
|
@private
|
||||||
_lstat :: proc(path: string) -> (OS_Stat, Errno) {
|
_lstat :: proc(path: string) -> (OS_Stat, Error) {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
|
|
||||||
@@ -794,7 +794,7 @@ _lstat :: proc(path: string) -> (OS_Stat, Errno) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@private
|
@private
|
||||||
_fstat :: proc(fd: Handle) -> (OS_Stat, Errno) {
|
_fstat :: proc(fd: Handle) -> (OS_Stat, Error) {
|
||||||
// deliberately uninitialized; the syscall fills this buffer for us
|
// deliberately uninitialized; the syscall fills this buffer for us
|
||||||
s: OS_Stat = ---
|
s: OS_Stat = ---
|
||||||
result := unix.sys_fstat(int(fd), rawptr(&s))
|
result := unix.sys_fstat(int(fd), rawptr(&s))
|
||||||
@@ -805,19 +805,19 @@ _fstat :: proc(fd: Handle) -> (OS_Stat, Errno) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@private
|
@private
|
||||||
_fdopendir :: proc(fd: Handle) -> (Dir, Errno) {
|
_fdopendir :: proc(fd: Handle) -> (Dir, Error) {
|
||||||
dirp := _unix_fdopendir(fd)
|
dirp := _unix_fdopendir(fd)
|
||||||
if dirp == cast(Dir)nil {
|
if dirp == cast(Dir)nil {
|
||||||
return nil, Errno(get_last_error())
|
return nil, Error(get_last_error())
|
||||||
}
|
}
|
||||||
return dirp, nil
|
return dirp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@private
|
@private
|
||||||
_closedir :: proc(dirp: Dir) -> Errno {
|
_closedir :: proc(dirp: Dir) -> Error {
|
||||||
rc := _unix_closedir(dirp)
|
rc := _unix_closedir(dirp)
|
||||||
if rc != 0 {
|
if rc != 0 {
|
||||||
return Errno(get_last_error())
|
return Error(get_last_error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -828,12 +828,12 @@ _rewinddir :: proc(dirp: Dir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@private
|
@private
|
||||||
_readdir :: proc(dirp: Dir) -> (entry: Dirent, err: Errno, end_of_stream: bool) {
|
_readdir :: proc(dirp: Dir) -> (entry: Dirent, err: Error, end_of_stream: bool) {
|
||||||
result: ^Dirent
|
result: ^Dirent
|
||||||
rc := _unix_readdir_r(dirp, &entry, &result)
|
rc := _unix_readdir_r(dirp, &entry, &result)
|
||||||
|
|
||||||
if rc != 0 {
|
if rc != 0 {
|
||||||
err = Errno(get_last_error())
|
err = Error(get_last_error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = nil
|
err = nil
|
||||||
@@ -848,7 +848,7 @@ _readdir :: proc(dirp: Dir) -> (entry: Dirent, err: Errno, end_of_stream: bool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
@private
|
@private
|
||||||
_readlink :: proc(path: string) -> (string, Errno) {
|
_readlink :: proc(path: string) -> (string, Error) {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == context.allocator)
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == context.allocator)
|
||||||
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
path_cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
|
|
||||||
@@ -870,7 +870,7 @@ _readlink :: proc(path: string) -> (string, Errno) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
absolute_path_from_handle :: proc(fd: Handle) -> (string, Errno) {
|
absolute_path_from_handle :: proc(fd: Handle) -> (string, Error) {
|
||||||
buf : [256]byte
|
buf : [256]byte
|
||||||
fd_str := strconv.itoa( buf[:], cast(int)fd )
|
fd_str := strconv.itoa( buf[:], cast(int)fd )
|
||||||
|
|
||||||
@@ -880,7 +880,7 @@ absolute_path_from_handle :: proc(fd: Handle) -> (string, Errno) {
|
|||||||
return _readlink(procfs_path)
|
return _readlink(procfs_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Errno) {
|
absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Error) {
|
||||||
rel := rel
|
rel := rel
|
||||||
if rel == "" {
|
if rel == "" {
|
||||||
rel = "."
|
rel = "."
|
||||||
@@ -891,7 +891,7 @@ absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Errno) {
|
|||||||
|
|
||||||
path_ptr := _unix_realpath(rel_cstr, nil)
|
path_ptr := _unix_realpath(rel_cstr, nil)
|
||||||
if path_ptr == nil {
|
if path_ptr == nil {
|
||||||
return "", Errno(get_last_error())
|
return "", Error(get_last_error())
|
||||||
}
|
}
|
||||||
defer _unix_free(path_ptr)
|
defer _unix_free(path_ptr)
|
||||||
|
|
||||||
@@ -900,7 +900,7 @@ absolute_path_from_relative :: proc(rel: string) -> (path: string, err: Errno) {
|
|||||||
return path, nil
|
return path, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
access :: proc(path: string, mask: int) -> (bool, Errno) {
|
access :: proc(path: string, mask: int) -> (bool, Error) {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
result := unix.sys_access(cstr, mask)
|
result := unix.sys_access(cstr, mask)
|
||||||
@@ -926,24 +926,24 @@ get_env :: proc(key: string, allocator := context.allocator) -> (value: string)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
set_env :: proc(key, value: string) -> Errno {
|
set_env :: proc(key, value: string) -> Error {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
key_cstring := strings.clone_to_cstring(key, context.temp_allocator)
|
key_cstring := strings.clone_to_cstring(key, context.temp_allocator)
|
||||||
value_cstring := strings.clone_to_cstring(value, context.temp_allocator)
|
value_cstring := strings.clone_to_cstring(value, context.temp_allocator)
|
||||||
// NOTE(GoNZooo): `setenv` instead of `putenv` because it copies both key and value more commonly
|
// NOTE(GoNZooo): `setenv` instead of `putenv` because it copies both key and value more commonly
|
||||||
res := _unix_setenv(key_cstring, value_cstring, 1)
|
res := _unix_setenv(key_cstring, value_cstring, 1)
|
||||||
if res < 0 {
|
if res < 0 {
|
||||||
return Errno(get_last_error())
|
return Error(get_last_error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
unset_env :: proc(key: string) -> Errno {
|
unset_env :: proc(key: string) -> Error {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
s := strings.clone_to_cstring(key, context.temp_allocator)
|
s := strings.clone_to_cstring(key, context.temp_allocator)
|
||||||
res := _unix_putenv(s)
|
res := _unix_putenv(s)
|
||||||
if res < 0 {
|
if res < 0 {
|
||||||
return Errno(get_last_error())
|
return Error(get_last_error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -969,7 +969,7 @@ get_current_directory :: proc() -> string {
|
|||||||
unreachable()
|
unreachable()
|
||||||
}
|
}
|
||||||
|
|
||||||
set_current_directory :: proc(path: string) -> (err: Errno) {
|
set_current_directory :: proc(path: string) -> (err: Error) {
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
cstr := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
res := unix.sys_chdir(cstr)
|
res := unix.sys_chdir(cstr)
|
||||||
@@ -1034,7 +1034,7 @@ _alloc_command_line_arguments :: proc() -> []string {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
socket :: proc(domain: int, type: int, protocol: int) -> (Socket, Errno) {
|
socket :: proc(domain: int, type: int, protocol: int) -> (Socket, Error) {
|
||||||
result := unix.sys_socket(domain, type, protocol)
|
result := unix.sys_socket(domain, type, protocol)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return 0, _get_errno(result)
|
return 0, _get_errno(result)
|
||||||
@@ -1042,7 +1042,7 @@ socket :: proc(domain: int, type: int, protocol: int) -> (Socket, Errno) {
|
|||||||
return Socket(result), nil
|
return Socket(result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
bind :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Errno) {
|
bind :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Error) {
|
||||||
result := unix.sys_bind(int(sd), addr, len)
|
result := unix.sys_bind(int(sd), addr, len)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return _get_errno(result)
|
return _get_errno(result)
|
||||||
@@ -1051,7 +1051,7 @@ bind :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Errno) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
connect :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Errno) {
|
connect :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Error) {
|
||||||
result := unix.sys_connect(int(sd), addr, len)
|
result := unix.sys_connect(int(sd), addr, len)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return _get_errno(result)
|
return _get_errno(result)
|
||||||
@@ -1059,7 +1059,7 @@ connect :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Errno) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
accept :: proc(sd: Socket, addr: ^SOCKADDR, len: rawptr) -> (Socket, Errno) {
|
accept :: proc(sd: Socket, addr: ^SOCKADDR, len: rawptr) -> (Socket, Error) {
|
||||||
result := unix.sys_accept(int(sd), rawptr(addr), len)
|
result := unix.sys_accept(int(sd), rawptr(addr), len)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return 0, _get_errno(result)
|
return 0, _get_errno(result)
|
||||||
@@ -1067,7 +1067,7 @@ accept :: proc(sd: Socket, addr: ^SOCKADDR, len: rawptr) -> (Socket, Errno) {
|
|||||||
return Socket(result), nil
|
return Socket(result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
listen :: proc(sd: Socket, backlog: int) -> (Errno) {
|
listen :: proc(sd: Socket, backlog: int) -> (Error) {
|
||||||
result := unix.sys_listen(int(sd), backlog)
|
result := unix.sys_listen(int(sd), backlog)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return _get_errno(result)
|
return _get_errno(result)
|
||||||
@@ -1075,7 +1075,7 @@ listen :: proc(sd: Socket, backlog: int) -> (Errno) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
setsockopt :: proc(sd: Socket, level: int, optname: int, optval: rawptr, optlen: socklen_t) -> (Errno) {
|
setsockopt :: proc(sd: Socket, level: int, optname: int, optval: rawptr, optlen: socklen_t) -> (Error) {
|
||||||
result := unix.sys_setsockopt(int(sd), level, optname, optval, optlen)
|
result := unix.sys_setsockopt(int(sd), level, optname, optval, optlen)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return _get_errno(result)
|
return _get_errno(result)
|
||||||
@@ -1084,7 +1084,7 @@ setsockopt :: proc(sd: Socket, level: int, optname: int, optval: rawptr, optlen:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
recvfrom :: proc(sd: Socket, data: []byte, flags: int, addr: ^SOCKADDR, addr_size: ^socklen_t) -> (u32, Errno) {
|
recvfrom :: proc(sd: Socket, data: []byte, flags: int, addr: ^SOCKADDR, addr_size: ^socklen_t) -> (u32, Error) {
|
||||||
result := unix.sys_recvfrom(int(sd), raw_data(data), len(data), flags, addr, uintptr(addr_size))
|
result := unix.sys_recvfrom(int(sd), raw_data(data), len(data), flags, addr, uintptr(addr_size))
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return 0, _get_errno(int(result))
|
return 0, _get_errno(int(result))
|
||||||
@@ -1092,7 +1092,7 @@ recvfrom :: proc(sd: Socket, data: []byte, flags: int, addr: ^SOCKADDR, addr_siz
|
|||||||
return u32(result), nil
|
return u32(result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
recv :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Errno) {
|
recv :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Error) {
|
||||||
result := unix.sys_recvfrom(int(sd), raw_data(data), len(data), flags, nil, 0)
|
result := unix.sys_recvfrom(int(sd), raw_data(data), len(data), flags, nil, 0)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return 0, _get_errno(int(result))
|
return 0, _get_errno(int(result))
|
||||||
@@ -1101,7 +1101,7 @@ recv :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Errno) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sendto :: proc(sd: Socket, data: []u8, flags: int, addr: ^SOCKADDR, addrlen: socklen_t) -> (u32, Errno) {
|
sendto :: proc(sd: Socket, data: []u8, flags: int, addr: ^SOCKADDR, addrlen: socklen_t) -> (u32, Error) {
|
||||||
result := unix.sys_sendto(int(sd), raw_data(data), len(data), flags, addr, addrlen)
|
result := unix.sys_sendto(int(sd), raw_data(data), len(data), flags, addr, addrlen)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return 0, _get_errno(int(result))
|
return 0, _get_errno(int(result))
|
||||||
@@ -1109,7 +1109,7 @@ sendto :: proc(sd: Socket, data: []u8, flags: int, addr: ^SOCKADDR, addrlen: soc
|
|||||||
return u32(result), nil
|
return u32(result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
send :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Errno) {
|
send :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Error) {
|
||||||
result := unix.sys_sendto(int(sd), raw_data(data), len(data), 0, nil, 0)
|
result := unix.sys_sendto(int(sd), raw_data(data), len(data), 0, nil, 0)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return 0, _get_errno(int(result))
|
return 0, _get_errno(int(result))
|
||||||
@@ -1117,7 +1117,7 @@ send :: proc(sd: Socket, data: []byte, flags: int) -> (u32, Errno) {
|
|||||||
return u32(result), nil
|
return u32(result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
shutdown :: proc(sd: Socket, how: int) -> (Errno) {
|
shutdown :: proc(sd: Socket, how: int) -> (Error) {
|
||||||
result := unix.sys_shutdown(int(sd), how)
|
result := unix.sys_shutdown(int(sd), how)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return _get_errno(result)
|
return _get_errno(result)
|
||||||
@@ -1125,7 +1125,7 @@ shutdown :: proc(sd: Socket, how: int) -> (Errno) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fcntl :: proc(fd: int, cmd: int, arg: int) -> (int, Errno) {
|
fcntl :: proc(fd: int, cmd: int, arg: int) -> (int, Error) {
|
||||||
result := unix.sys_fcntl(fd, cmd, arg)
|
result := unix.sys_fcntl(fd, cmd, arg)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return 0, _get_errno(result)
|
return 0, _get_errno(result)
|
||||||
@@ -1133,7 +1133,7 @@ fcntl :: proc(fd: int, cmd: int, arg: int) -> (int, Errno) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
poll :: proc(fds: []pollfd, timeout: int) -> (int, Errno) {
|
poll :: proc(fds: []pollfd, timeout: int) -> (int, Error) {
|
||||||
result := unix.sys_poll(raw_data(fds), uint(len(fds)), timeout)
|
result := unix.sys_poll(raw_data(fds), uint(len(fds)), timeout)
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return 0, _get_errno(result)
|
return 0, _get_errno(result)
|
||||||
@@ -1141,7 +1141,7 @@ poll :: proc(fds: []pollfd, timeout: int) -> (int, Errno) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ppoll :: proc(fds: []pollfd, timeout: ^unix.timespec, sigmask: ^sigset_t) -> (int, Errno) {
|
ppoll :: proc(fds: []pollfd, timeout: ^unix.timespec, sigmask: ^sigset_t) -> (int, Error) {
|
||||||
result := unix.sys_ppoll(raw_data(fds), uint(len(fds)), timeout, sigmask, size_of(sigset_t))
|
result := unix.sys_ppoll(raw_data(fds), uint(len(fds)), timeout, sigmask, size_of(sigset_t))
|
||||||
if result < 0 {
|
if result < 0 {
|
||||||
return 0, _get_errno(result)
|
return 0, _get_errno(result)
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ get_last_error :: proc "contextless" () -> Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
last_write_time :: proc(fd: Handle) -> (File_Time, Errno) {
|
last_write_time :: proc(fd: Handle) -> (File_Time, Error) {
|
||||||
file_info: win32.BY_HANDLE_FILE_INFORMATION
|
file_info: win32.BY_HANDLE_FILE_INFORMATION
|
||||||
if !win32.GetFileInformationByHandle(win32.HANDLE(fd), &file_info) {
|
if !win32.GetFileInformationByHandle(win32.HANDLE(fd), &file_info) {
|
||||||
return 0, get_last_error()
|
return 0, get_last_error()
|
||||||
@@ -124,7 +124,7 @@ last_write_time :: proc(fd: Handle) -> (File_Time, Errno) {
|
|||||||
return lo | hi << 32, nil
|
return lo | hi << 32, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
last_write_time_by_name :: proc(name: string) -> (File_Time, Errno) {
|
last_write_time_by_name :: proc(name: string) -> (File_Time, Error) {
|
||||||
data: win32.WIN32_FILE_ATTRIBUTE_DATA
|
data: win32.WIN32_FILE_ATTRIBUTE_DATA
|
||||||
|
|
||||||
wide_path := win32.utf8_to_wstring(name)
|
wide_path := win32.utf8_to_wstring(name)
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ path_base :: proc(path: string) -> string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
lstat :: proc(name: string, allocator := context.allocator) -> (fi: File_Info, err: Errno) {
|
lstat :: proc(name: string, allocator := context.allocator) -> (fi: File_Info, err: Error) {
|
||||||
context.allocator = allocator
|
context.allocator = allocator
|
||||||
|
|
||||||
s := _lstat(name) or_return
|
s := _lstat(name) or_return
|
||||||
@@ -110,7 +110,7 @@ lstat :: proc(name: string, allocator := context.allocator) -> (fi: File_Info, e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
stat :: proc(name: string, allocator := context.allocator) -> (fi: File_Info, err: Errno) {
|
stat :: proc(name: string, allocator := context.allocator) -> (fi: File_Info, err: Error) {
|
||||||
context.allocator = allocator
|
context.allocator = allocator
|
||||||
|
|
||||||
s := _stat(name) or_return
|
s := _stat(name) or_return
|
||||||
@@ -120,7 +120,7 @@ stat :: proc(name: string, allocator := context.allocator) -> (fi: File_Info, er
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fstat :: proc(fd: Handle, allocator := context.allocator) -> (fi: File_Info, err: Errno) {
|
fstat :: proc(fd: Handle, allocator := context.allocator) -> (fi: File_Info, err: Error) {
|
||||||
context.allocator = allocator
|
context.allocator = allocator
|
||||||
|
|
||||||
s := _fstat(fd) or_return
|
s := _fstat(fd) or_return
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ stream_from_handle :: proc(fd: Handle) -> io.Stream {
|
|||||||
_file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, offset: i64, whence: io.Seek_From) -> (n: i64, err: io.Error) {
|
_file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, offset: i64, whence: io.Seek_From) -> (n: i64, err: io.Error) {
|
||||||
fd := Handle(uintptr(stream_data))
|
fd := Handle(uintptr(stream_data))
|
||||||
n_int: int
|
n_int: int
|
||||||
os_err: Errno
|
os_err: Error
|
||||||
switch mode {
|
switch mode {
|
||||||
case .Close:
|
case .Close:
|
||||||
close(fd)
|
close(fd)
|
||||||
|
|||||||
Reference in New Issue
Block a user