aboutsummaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2021-05-20 12:15:14 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2021-05-20 12:15:14 +0200
commit44ee0f2cdc773fc3ba3261de076b8a8a7fb64f03 (patch)
treec408237d1bd2e6bfcb0c5526d9c0d8cdb97bbf69 /core/os
parent50035f257eb33769211ca49a30c51f9a20440a0e (diff)
parent92abddddc5ca4be622e93856c7246159b594e9e9 (diff)
Merge branch 'master' into prototype-fmt
Diffstat (limited to 'core/os')
-rw-r--r--core/os/os2/errors.odin61
-rw-r--r--core/os/os2/file_stream.odin23
-rw-r--r--core/os/os2/file_util.odin1
-rw-r--r--core/os/os2/file_windows.odin20
-rw-r--r--core/os/os2/pipe_windows.odin2
-rw-r--r--core/os/os2/stat_windows.odin6
-rw-r--r--core/os/os2/temp_file_windows.odin4
-rw-r--r--core/os/os_freebsd.odin2
-rw-r--r--core/os/os_linux.odin6
9 files changed, 44 insertions, 81 deletions
diff --git a/core/os/os2/errors.odin b/core/os/os2/errors.odin
index 00cd600a8..2fc49deed 100644
--- a/core/os/os2/errors.odin
+++ b/core/os/os2/errors.odin
@@ -1,11 +1,8 @@
package os2
-Platform_Error_Min_Bits :: 32;
+import "core:io"
-Error :: enum u64 {
- None = 0,
-
- // General Errors
+General_Error :: enum u32 {
Invalid_Argument,
Permission_Denied,
@@ -13,42 +10,19 @@ Error :: enum u64 {
Not_Exist,
Closed,
- // Timeout Errors
Timeout,
+}
- // I/O Errors
- // EOF is the error returned by `read` when no more input is available
- EOF,
-
- // Unexpected_EOF means that EOF was encountered in the middle of reading a fixed-sized block of data
- Unexpected_EOF,
-
- // Short_Write means that a write accepted fewer bytes than requested but failed to return an explicit error
- Short_Write,
-
- // Invalid_Write means that a write returned an impossible count
- Invalid_Write,
-
- // Short_Buffer means that a read required a longer buffer than was provided
- Short_Buffer,
-
- // No_Progress is returned by some implementations of `io.Reader` when many calls
- // to `read` have failed to return any data or error.
- // This is usually a signed of a broken `io.Reader` implementation
- No_Progress,
-
- Invalid_Whence,
- Invalid_Offset,
- Invalid_Unread,
-
- Negative_Read,
- Negative_Write,
- Negative_Count,
- Buffer_Full,
+Platform_Error :: struct {
+ err: i32,
+}
- // Platform Specific Errors
- Platform_Minimum = 1<<Platform_Error_Min_Bits,
+Error :: union {
+ General_Error,
+ io.Error,
+ Platform_Error,
}
+#assert(size_of(Error) == size_of(u64));
Path_Error :: struct {
op: string,
@@ -83,20 +57,17 @@ link_error_delete :: proc(lerr: Maybe(Link_Error)) {
is_platform_error :: proc(ferr: Error) -> (err: i32, ok: bool) {
- if ferr >= .Platform_Minimum {
- err = i32(u64(ferr)>>Platform_Error_Min_Bits);
- ok = true;
+ v: Platform_Error;
+ if v, ok = ferr.(Platform_Error); ok {
+ err = v.err;
}
return;
}
-error_from_platform_error :: proc(errno: i32) -> Error {
- return Error(u64(errno) << Platform_Error_Min_Bits);
-}
error_string :: proc(ferr: Error) -> string {
- #partial switch ferr {
- case .None: return "";
+ switch ferr {
+ case nil: return "";
case .Invalid_Argument: return "invalid argument";
case .Permission_Denied: return "permission denied";
case .Exist: return "file already exists";
diff --git a/core/os/os2/file_stream.odin b/core/os/os2/file_stream.odin
index 6877faea4..52f5b30e9 100644
--- a/core/os/os2/file_stream.odin
+++ b/core/os/os2/file_stream.odin
@@ -10,23 +10,14 @@ file_to_stream :: proc(fd: Handle) -> (s: io.Stream) {
@(private)
error_to_io_error :: proc(ferr: Error) -> io.Error {
- #partial switch ferr {
- case .None: return .None;
- case .EOF: return .EOF;
- case .Unexpected_EOF: return .Unexpected_EOF;
- case .Short_Write: return .Short_Write;
- case .Invalid_Write: return .Invalid_Write;
- case .Short_Buffer: return .Short_Buffer;
- case .No_Progress: return .No_Progress;
- case .Invalid_Whence: return .Invalid_Whence;
- case .Invalid_Offset: return .Invalid_Offset;
- case .Invalid_Unread: return .Invalid_Unread;
- case .Negative_Read: return .Negative_Read;
- case .Negative_Write: return .Negative_Write;
- case .Negative_Count: return .Negative_Count;
- case .Buffer_Full: return .Buffer_Full;
+ if ferr == nil {
+ return .None;
}
- return .Unknown;
+ err, ok := ferr.(io.Error);
+ if !ok {
+ err = .Unknown;
+ }
+ return err;
}
diff --git a/core/os/os2/file_util.odin b/core/os/os2/file_util.odin
index 435eba3ab..db6842cf8 100644
--- a/core/os/os2/file_util.odin
+++ b/core/os/os2/file_util.odin
@@ -1,6 +1,7 @@
package os2
import "core:mem"
+import "core:io"
import "core:strconv"
import "core:unicode/utf8"
diff --git a/core/os/os2/file_windows.odin b/core/os/os2/file_windows.odin
index 97fe6b3d9..5e87d80a4 100644
--- a/core/os/os2/file_windows.odin
+++ b/core/os/os2/file_windows.odin
@@ -5,19 +5,19 @@ import "core:io"
import "core:time"
_create :: proc(name: string) -> (Handle, Error) {
- return 0, .None;
+ return 0, nil;
}
_open :: proc(name: string) -> (Handle, Error) {
- return 0, .None;
+ return 0, nil;
}
_open_file :: proc(name: string, flag: int, perm: File_Mode) -> (Handle, Error) {
- return 0, .None;
+ return 0, nil;
}
_close :: proc(fd: Handle) -> Error {
- return .None;
+ return nil;
}
_name :: proc(fd: Handle, allocator := context.allocator) -> string {
@@ -58,11 +58,11 @@ _file_size :: proc(fd: Handle) -> (n: i64, err: Error) {
_sync :: proc(fd: Handle) -> Error {
- return .None;
+ return nil;
}
_flush :: proc(fd: Handle) -> Error {
- return .None;
+ return nil;
}
_truncate :: proc(fd: Handle, size: i64) -> Maybe(Path_Error) {
@@ -92,20 +92,20 @@ _read_link :: proc(name: string) -> (string, Maybe(Path_Error)) {
_chdir :: proc(fd: Handle) -> Error {
- return .None;
+ return nil;
}
_chmod :: proc(fd: Handle, mode: File_Mode) -> Error {
- return .None;
+ return nil;
}
_chown :: proc(fd: Handle, uid, gid: int) -> Error {
- return .None;
+ return nil;
}
_lchown :: proc(name: string, uid, gid: int) -> Error {
- return .None;
+ return nil;
}
diff --git a/core/os/os2/pipe_windows.odin b/core/os/os2/pipe_windows.odin
index 68adb6c3b..04750bf88 100644
--- a/core/os/os2/pipe_windows.odin
+++ b/core/os/os2/pipe_windows.odin
@@ -6,7 +6,7 @@ import win32 "core:sys/windows"
_pipe :: proc() -> (r, w: Handle, err: Error) {
p: [2]win32.HANDLE;
if !win32.CreatePipe(&p[0], &p[1], nil, 0) {
- return 0, 0, error_from_platform_error(i32(win32.GetLastError()));
+ return 0, 0, Platform_Error{i32(win32.GetLastError())};
}
return Handle(p[0]), Handle(p[1]), nil;
}
diff --git a/core/os/os2/stat_windows.odin b/core/os/os2/stat_windows.odin
index ed739b894..48811340a 100644
--- a/core/os/os2/stat_windows.odin
+++ b/core/os/os2/stat_windows.odin
@@ -40,7 +40,7 @@ _same_file :: proc(fi1, fi2: File_Info) -> bool {
_stat_errno :: proc(errno: win32.DWORD) -> Path_Error {
- return Path_Error{err = error_from_platform_error(i32(errno))};
+ return Path_Error{err = Platform_Error{i32(errno)}};
}
@@ -89,7 +89,7 @@ internal_stat :: proc(name: string, create_file_attributes: u32, allocator := co
fd: win32.WIN32_FIND_DATAW;
sh := win32.FindFirstFileW(wname, &fd);
if sh == win32.INVALID_HANDLE_VALUE {
- e = Path_Error{err = error_from_platform_error(i32(win32.GetLastError()))};
+ e = Path_Error{err = Platform_Error{i32(win32.GetLastError())}};
return;
}
win32.FindClose(sh);
@@ -99,7 +99,7 @@ internal_stat :: proc(name: string, create_file_attributes: u32, allocator := co
h := win32.CreateFileW(wname, 0, 0, nil, win32.OPEN_EXISTING, create_file_attributes, nil);
if h == win32.INVALID_HANDLE_VALUE {
- e = Path_Error{err = error_from_platform_error(i32(win32.GetLastError()))};
+ e = Path_Error{err = Platform_Error{i32(win32.GetLastError())}};
return;
}
defer win32.CloseHandle(h);
diff --git a/core/os/os2/temp_file_windows.odin b/core/os/os2/temp_file_windows.odin
index 19dca1b04..dd050ab48 100644
--- a/core/os/os2/temp_file_windows.odin
+++ b/core/os/os2/temp_file_windows.odin
@@ -4,11 +4,11 @@ package os2
import win32 "core:sys/windows"
_create_temp :: proc(dir, pattern: string) -> (Handle, Error) {
- return 0, .None;
+ return 0, nil;
}
_mkdir_temp :: proc(dir, pattern: string, allocator := context.allocator) -> (string, Error) {
- return "", .None;
+ return "", nil;
}
_temp_dir :: proc(allocator := context.allocator) -> string {
diff --git a/core/os/os_freebsd.odin b/core/os/os_freebsd.odin
index 137c6f864..2afa8bd14 100644
--- a/core/os/os_freebsd.odin
+++ b/core/os/os_freebsd.odin
@@ -10,7 +10,7 @@ import "core:c"
Handle :: distinct i32;
File_Time :: distinct u64;
Errno :: distinct i32;
-Syscall :: distinct int;
+Syscall :: distinct i32;
INVALID_HANDLE :: ~Handle(0);
diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin
index dd0914f40..7569909d7 100644
--- a/core/os/os_linux.odin
+++ b/core/os/os_linux.odin
@@ -11,7 +11,7 @@ import "core:strconv"
Handle :: distinct i32;
File_Time :: distinct u64;
Errno :: distinct i32;
-Syscall :: distinct int;
+Syscall :: distinct i32;
INVALID_HANDLE :: ~Handle(0);
@@ -269,7 +269,7 @@ SYS_GETTID: Syscall : 186;
foreign libc {
@(link_name="__errno_location") __errno_location :: proc() -> ^int ---;
- @(link_name="syscall") syscall :: proc(number: Syscall, #c_vararg args: ..any) -> int ---;
+ @(link_name="syscall") syscall :: proc(number: Syscall, #c_vararg args: ..any) -> i32 ---;
@(link_name="open") _unix_open :: proc(path: cstring, flags: c.int, mode: c.int) -> Handle ---;
@(link_name="close") _unix_close :: proc(fd: Handle) -> c.int ---;
@@ -595,7 +595,7 @@ exit :: proc "contextless" (code: int) -> ! {
}
current_thread_id :: proc "contextless" () -> int {
- return syscall(SYS_GETTID);
+ return cast(int)syscall(SYS_GETTID);
}
dlopen :: proc(filename: string, flags: int) -> rawptr {