浏览代码

Clean up error handling

gingerBill 1 年之前
父节点
当前提交
29b6eebcd5

+ 2 - 2
core/os/dir_windows.odin

@@ -88,7 +88,7 @@ read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []F
 	find_data := &win32.WIN32_FIND_DATAW{}
 	find_data := &win32.WIN32_FIND_DATAW{}
 	find_handle := win32.FindFirstFileW(raw_data(wpath_search), find_data)
 	find_handle := win32.FindFirstFileW(raw_data(wpath_search), find_data)
 	if find_handle == win32.INVALID_HANDLE_VALUE {
 	if find_handle == win32.INVALID_HANDLE_VALUE {
-		err = Platform_Error(win32.GetLastError())
+		err = get_last_error()
 		return dfi[:], err
 		return dfi[:], err
 	}
 	}
 	defer win32.FindClose(find_handle)
 	defer win32.FindClose(find_handle)
@@ -101,7 +101,7 @@ read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []F
 		}
 		}
 
 
 		if !win32.FindNextFileW(find_handle, find_data) {
 		if !win32.FindNextFileW(find_handle, find_data) {
-			e := Platform_Error(win32.GetLastError())
+			e := get_last_error()
 			if e == ERROR_NO_MORE_FILES {
 			if e == ERROR_NO_MORE_FILES {
 				break
 				break
 			}
 			}

+ 8 - 14
core/os/env_windows.odin

@@ -13,21 +13,15 @@ lookup_env :: proc(key: string, allocator := context.allocator) -> (value: strin
 	}
 	}
 	wkey := win32.utf8_to_wstring(key)
 	wkey := win32.utf8_to_wstring(key)
 	n := win32.GetEnvironmentVariableW(wkey, nil, 0)
 	n := win32.GetEnvironmentVariableW(wkey, nil, 0)
-	if n == 0 {
-		err := win32.GetLastError()
-		if err == u32(ERROR_ENVVAR_NOT_FOUND) {
-			return "", false
-		}
+	if n == 0 && get_last_error() == ERROR_ENVVAR_NOT_FOUND {
+		return "", false
 	}
 	}
 	runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == allocator)
 	runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == allocator)
 
 
 	b := make([dynamic]u16, n, context.temp_allocator)
 	b := make([dynamic]u16, n, context.temp_allocator)
 	n = win32.GetEnvironmentVariableW(wkey, raw_data(b), u32(len(b)))
 	n = win32.GetEnvironmentVariableW(wkey, raw_data(b), u32(len(b)))
-	if n == 0 {
-		err := win32.GetLastError()
-		if err == u32(ERROR_ENVVAR_NOT_FOUND) {
-			return "", false
-		}
+	if n == 0 && get_last_error() == ERROR_ENVVAR_NOT_FOUND {
+		return "", false
 	}
 	}
 	value, _ = win32.utf16_to_utf8(b[:n], allocator)
 	value, _ = win32.utf16_to_utf8(b[:n], allocator)
 	found = true
 	found = true
@@ -50,18 +44,18 @@ set_env :: proc(key, value: string) -> Errno {
 	v := win32.utf8_to_wstring(value)
 	v := win32.utf8_to_wstring(value)
 
 
 	if !win32.SetEnvironmentVariableW(k, v) {
 	if !win32.SetEnvironmentVariableW(k, v) {
-		return Platform_Error(win32.GetLastError())
+		return get_last_error()
 	}
 	}
-	return 0
+	return nil
 }
 }
 
 
 // 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) -> Errno {
 	k := win32.utf8_to_wstring(key)
 	k := win32.utf8_to_wstring(key)
 	if !win32.SetEnvironmentVariableW(k, nil) {
 	if !win32.SetEnvironmentVariableW(k, nil) {
-		return Platform_Error(win32.GetLastError())
+		return get_last_error()
 	}
 	}
-	return 0
+	return nil
 }
 }
 
 
 // environ returns a copy of strings representing the environment, in the form "key=value"
 // environ returns a copy of strings representing the environment, in the form "key=value"

+ 31 - 42
core/os/file_windows.odin

@@ -55,20 +55,20 @@ open :: proc(path: string, mode: int = O_RDONLY, perm: int = 0) -> (Handle, Errn
 		return handle, ERROR_NONE
 		return handle, ERROR_NONE
 	}
 	}
 
 
-	err := Platform_Error(win32.GetLastError())
+	err := get_last_error()
 	return INVALID_HANDLE, err
 	return INVALID_HANDLE, err
 }
 }
 
 
 close :: proc(fd: Handle) -> Errno {
 close :: proc(fd: Handle) -> Errno {
 	if !win32.CloseHandle(win32.HANDLE(fd)) {
 	if !win32.CloseHandle(win32.HANDLE(fd)) {
-		return Platform_Error(win32.GetLastError())
+		return get_last_error()
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 flush :: proc(fd: Handle) -> (err: Errno) {
 flush :: proc(fd: Handle) -> (err: Errno) {
 	if !win32.FlushFileBuffers(win32.HANDLE(fd)) {
 	if !win32.FlushFileBuffers(win32.HANDLE(fd)) {
-		err = Platform_Error(win32.GetLastError())
+		err = get_last_error()
 	}
 	}
 	return
 	return
 }
 }
@@ -90,8 +90,7 @@ write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
 
 
 		e := win32.WriteFile(win32.HANDLE(fd), &data[total_write], to_write, &single_write_length, nil)
 		e := win32.WriteFile(win32.HANDLE(fd), &data[total_write], to_write, &single_write_length, nil)
 		if single_write_length <= 0 || !e {
 		if single_write_length <= 0 || !e {
-			err := Platform_Error(win32.GetLastError())
-			return int(total_write), err
+			return int(total_write), get_last_error()
 		}
 		}
 		total_write += i64(single_write_length)
 		total_write += i64(single_write_length)
 	}
 	}
@@ -101,14 +100,14 @@ 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: Errno) {
 	if len(b) == 0 {
 	if len(b) == 0 {
-		return 0, 0
+		return 0, nil
 	}
 	}
 	
 	
 	BUF_SIZE :: 386
 	BUF_SIZE :: 386
 	buf16: [BUF_SIZE]u16
 	buf16: [BUF_SIZE]u16
 	buf8: [4*BUF_SIZE]u8
 	buf8: [4*BUF_SIZE]u8
 
 
-	for n < len(b) && err == 0 {
+	for n < len(b) && err == nil {
 		min_read := max(len(b)/4, 1 if len(b) > 0 else 0)
 		min_read := max(len(b)/4, 1 if len(b) > 0 else 0)
 		max_read := u32(min(BUF_SIZE, min_read))
 		max_read := u32(min(BUF_SIZE, min_read))
 		if max_read == 0 {
 		if max_read == 0 {
@@ -118,7 +117,7 @@ read_console :: proc(handle: win32.HANDLE, b: []byte) -> (n: int, err: Errno) {
 		single_read_length: u32
 		single_read_length: u32
 		ok := win32.ReadConsoleW(handle, &buf16[0], max_read, &single_read_length, nil)
 		ok := win32.ReadConsoleW(handle, &buf16[0], max_read, &single_read_length, nil)
 		if !ok {
 		if !ok {
-			err = Platform_Error(win32.GetLastError())
+			err = get_last_error()
 		}
 		}
 
 
 		buf8_len := utf16.decode_to_utf8(buf8[:], buf16[:single_read_length])
 		buf8_len := utf16.decode_to_utf8(buf8[:], buf16[:single_read_length])
@@ -165,7 +164,7 @@ read :: proc(fd: Handle, data: []byte) -> (total_read: int, err: Errno) {
 
 
 	if is_console {
 	if is_console {
 		total_read, err = read_console(handle, data[total_read:][:to_read])
 		total_read, err = read_console(handle, data[total_read:][:to_read])
-		if err != 0 {
+		if err != nil {
 			return total_read, err
 			return total_read, err
 		}
 		}
 	} else {
 	} else {
@@ -180,10 +179,10 @@ read :: proc(fd: Handle, data: []byte) -> (total_read: int, err: Errno) {
 				return int(bytes_read), ERROR_NONE
 				return int(bytes_read), ERROR_NONE
 			}
 			}
 		} else {
 		} else {
-			return 0, Platform_Error(win32.GetLastError())
+			return 0, get_last_error()
 		}
 		}
 	}
 	}
-	return total_read, ERROR_NONE
+	return total_read, nil
 }
 }
 
 
 seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
 seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
@@ -202,7 +201,7 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
 
 
 	dw_ptr := win32.SetFilePointer(win32.HANDLE(fd), lo, &hi, w)
 	dw_ptr := win32.SetFilePointer(win32.HANDLE(fd), lo, &hi, w)
 	if dw_ptr == win32.INVALID_SET_FILE_POINTER {
 	if dw_ptr == win32.INVALID_SET_FILE_POINTER {
-		err := Platform_Error(win32.GetLastError())
+		err := get_last_error()
 		return 0, err
 		return 0, err
 	}
 	}
 	return i64(hi)<<32 + i64(dw_ptr), ERROR_NONE
 	return i64(hi)<<32 + i64(dw_ptr), ERROR_NONE
@@ -212,7 +211,7 @@ file_size :: proc(fd: Handle) -> (i64, Errno) {
 	length: win32.LARGE_INTEGER
 	length: win32.LARGE_INTEGER
 	err: Errno
 	err: Errno
 	if !win32.GetFileSizeEx(win32.HANDLE(fd), &length) {
 	if !win32.GetFileSizeEx(win32.HANDLE(fd), &length) {
-		err = Platform_Error(win32.GetLastError())
+		err = get_last_error()
 	}
 	}
 	return i64(length), err
 	return i64(length), err
 }
 }
@@ -240,7 +239,7 @@ pread :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
 	done: win32.DWORD
 	done: win32.DWORD
 	e: Errno
 	e: Errno
 	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 = Platform_Error(win32.GetLastError())
+		e = get_last_error()
 		done = 0
 		done = 0
 	}
 	}
 	return int(done), e
 	return int(done), e
@@ -262,7 +261,7 @@ pwrite :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Errno) {
 	done: win32.DWORD
 	done: win32.DWORD
 	e: Errno
 	e: Errno
 	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 = Platform_Error(win32.GetLastError())
+		e = get_last_error()
 		done = 0
 		done = 0
 	}
 	}
 	return int(done), e
 	return int(done), e
@@ -287,10 +286,10 @@ read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Errno) {
 	for len(b) > 0 {
 	for len(b) > 0 {
 		m, e := pread(fd, b, offset)
 		m, e := pread(fd, b, offset)
 		if e == ERROR_EOF {
 		if e == ERROR_EOF {
-			err = 0
+			err = nil
 			break
 			break
 		}
 		}
-		if e != 0 {
+		if e != nil {
 			err = e
 			err = e
 			break
 			break
 		}
 		}
@@ -317,11 +316,7 @@ write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Errno)
 
 
 	b, offset := data, offset
 	b, offset := data, offset
 	for len(b) > 0 {
 	for len(b) > 0 {
-		m, e := pwrite(fd, b, offset)
-		if e != 0 {
-			err = e
-			break
-		}
+		m := pwrite(fd, b, offset) or_return
 		n += m
 		n += m
 		b = b[m:]
 		b = b[m:]
 		offset += i64(m)
 		offset += i64(m)
@@ -399,7 +394,7 @@ set_current_directory :: proc(path: string) -> (err: Errno) {
 	win32.AcquireSRWLockExclusive(&cwd_lock)
 	win32.AcquireSRWLockExclusive(&cwd_lock)
 
 
 	if !win32.SetCurrentDirectoryW(wstr) {
 	if !win32.SetCurrentDirectoryW(wstr) {
-		err = Platform_Error(win32.GetLastError())
+		err = get_last_error()
 	}
 	}
 
 
 	win32.ReleaseSRWLockExclusive(&cwd_lock)
 	win32.ReleaseSRWLockExclusive(&cwd_lock)
@@ -414,7 +409,7 @@ make_directory :: proc(path: string, mode: u32 = 0) -> (err: Errno) {
 	wpath := win32.utf8_to_wstring(path, context.temp_allocator)
 	wpath := win32.utf8_to_wstring(path, context.temp_allocator)
 
 
 	if !win32.CreateDirectoryW(wpath, nil) {
 	if !win32.CreateDirectoryW(wpath, nil) {
-		err = Platform_Error(win32.GetLastError())
+		err = get_last_error()
 	}
 	}
 	return
 	return
 }
 }
@@ -425,7 +420,7 @@ remove_directory :: proc(path: string) -> (err: Errno) {
 	wpath := win32.utf8_to_wstring(path, context.temp_allocator)
 	wpath := win32.utf8_to_wstring(path, context.temp_allocator)
 
 
 	if !win32.RemoveDirectoryW(wpath) {
 	if !win32.RemoveDirectoryW(wpath) {
-		err = Platform_Error(win32.GetLastError())
+		err = get_last_error()
 	}
 	}
 	return
 	return
 }
 }
@@ -505,7 +500,7 @@ unlink :: proc(path: string) -> (err: Errno) {
 	wpath := win32.utf8_to_wstring(path, context.temp_allocator)
 	wpath := win32.utf8_to_wstring(path, context.temp_allocator)
 
 
 	if !win32.DeleteFileW(wpath) {
 	if !win32.DeleteFileW(wpath) {
-		err = Platform_Error(win32.GetLastError())
+		err = get_last_error()
 	}
 	}
 	return
 	return
 }
 }
@@ -518,33 +513,27 @@ rename :: proc(old_path, new_path: string) -> (err: Errno) {
 	to := win32.utf8_to_wstring(new_path, context.temp_allocator)
 	to := win32.utf8_to_wstring(new_path, context.temp_allocator)
 
 
 	if !win32.MoveFileExW(from, to, win32.MOVEFILE_REPLACE_EXISTING) {
 	if !win32.MoveFileExW(from, to, win32.MOVEFILE_REPLACE_EXISTING) {
-		err = Platform_Error(win32.GetLastError())
+		err = get_last_error()
 	}
 	}
 	return
 	return
 }
 }
 
 
 
 
 ftruncate :: proc(fd: Handle, length: i64) -> (err: Errno) {
 ftruncate :: proc(fd: Handle, length: i64) -> (err: Errno) {
-	curr_off, e := seek(fd, 0, 1)
-	if e != 0 {
-		return e
-	}
+	curr_off := seek(fd, 0, 1) or_return
 	defer seek(fd, curr_off, 0)
 	defer seek(fd, curr_off, 0)
-	_, e = seek(fd, length, 0)
-	if e != 0 {
-		return e
-	}
+	_= seek(fd, length, 0) or_return
 	ok := win32.SetEndOfFile(win32.HANDLE(fd))
 	ok := win32.SetEndOfFile(win32.HANDLE(fd))
 	if !ok {
 	if !ok {
-		return Platform_Error(win32.GetLastError())
+		return get_last_error()
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 truncate :: proc(path: string, length: i64) -> (err: Errno) {
 truncate :: proc(path: string, length: i64) -> (err: Errno) {
 	fd: Handle
 	fd: Handle
 	fd, err = open(path, O_WRONLY|O_CREATE, 0o666)
 	fd, err = open(path, O_WRONLY|O_CREATE, 0o666)
-	if err != 0 {
+	if err != nil {
 		return
 		return
 	}
 	}
 	defer close(fd)
 	defer close(fd)
@@ -560,13 +549,13 @@ remove :: proc(name: string) -> Errno {
 		err = win32.GetLastError()
 		err = win32.GetLastError()
 	}
 	}
 	if err == 0 {
 	if err == 0 {
-		return 0
+		return nil
 	}
 	}
 	if !win32.RemoveDirectoryW(p) {
 	if !win32.RemoveDirectoryW(p) {
 		err1 = win32.GetLastError()
 		err1 = win32.GetLastError()
 	}
 	}
 	if err1 == 0 {
 	if err1 == 0 {
-		return 0
+		return nil
 	}
 	}
 
 
 	if err != err1 {
 	if err != err1 {
@@ -596,7 +585,7 @@ pipe :: proc() -> (r, w: Handle, err: Errno) {
 	sa.nLength = size_of(win32.SECURITY_ATTRIBUTES)
 	sa.nLength = size_of(win32.SECURITY_ATTRIBUTES)
 	sa.bInheritHandle = true
 	sa.bInheritHandle = true
 	if !win32.CreatePipe((^win32.HANDLE)(&r), (^win32.HANDLE)(&w), &sa, 0) {
 	if !win32.CreatePipe((^win32.HANDLE)(&r), (^win32.HANDLE)(&w), &sa, 0) {
-		err = Platform_Error(win32.GetLastError())
+		err = get_last_error()
 	}
 	}
 	return
 	return
 }
 }

+ 7 - 7
core/os/os.odin

@@ -91,7 +91,7 @@ read_at_least :: proc(fd: Handle, buf: []byte, min: int) -> (n: int, err: Errno)
 		return 0, io.Error.Short_Buffer
 		return 0, io.Error.Short_Buffer
 	}
 	}
 	nn := max(int)
 	nn := max(int)
-	for nn > 0 && n < min && err == 0 {
+	for nn > 0 && n < min && err == nil {
 		nn, err = read(fd, buf[n:])
 		nn, err = read(fd, buf[n:])
 		n += nn
 		n += nn
 	}
 	}
@@ -108,13 +108,13 @@ read_full :: proc(fd: Handle, buf: []byte) -> (n: int, err: Errno) {
 
 
 file_size_from_path :: proc(path: string) -> i64 {
 file_size_from_path :: proc(path: string) -> i64 {
 	fd, err := open(path, O_RDONLY, 0)
 	fd, err := open(path, O_RDONLY, 0)
-	if err != 0 {
+	if err != nil {
 		return -1
 		return -1
 	}
 	}
 	defer close(fd)
 	defer close(fd)
 
 
 	length: i64
 	length: i64
-	if length, err = file_size(fd); err != 0 {
+	if length, err = file_size(fd); err != nil {
 		return -1
 		return -1
 	}
 	}
 	return length
 	return length
@@ -124,7 +124,7 @@ read_entire_file_from_filename :: proc(name: string, allocator := context.alloca
 	context.allocator = allocator
 	context.allocator = allocator
 
 
 	fd, err := open(name, O_RDONLY, 0)
 	fd, err := open(name, O_RDONLY, 0)
-	if err != 0 {
+	if err != nil {
 		return nil, false
 		return nil, false
 	}
 	}
 	defer close(fd)
 	defer close(fd)
@@ -137,7 +137,7 @@ read_entire_file_from_handle :: proc(fd: Handle, allocator := context.allocator,
 
 
 	length: i64
 	length: i64
 	err: Errno
 	err: Errno
-	if length, err = file_size(fd); err != 0 {
+	if length, err = file_size(fd); err != nil {
 		return nil, false
 		return nil, false
 	}
 	}
 
 
@@ -176,13 +176,13 @@ write_entire_file :: proc(name: string, data: []byte, truncate := true) -> (succ
 	}
 	}
 
 
 	fd, err := open(name, flags, mode)
 	fd, err := open(name, flags, mode)
-	if err != 0 {
+	if err != nil {
 		return false
 		return false
 	}
 	}
 	defer close(fd)
 	defer close(fd)
 
 
 	_, write_err := write(fd, data)
 	_, write_err := write(fd, data)
-	return write_err == 0
+	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, Errno) {

+ 3 - 0
core/os/os2/file_util.odin

@@ -88,6 +88,9 @@ read_at_least :: proc(f: ^File, buf: []byte, min: int) -> (n: int, err: Error) {
 	return
 	return
 }
 }
 
 
+read_full :: proc(f: ^File, buf: []byte) -> (n: int, err: Error) {
+	return read_at_least(f, buf, len(buf))
+}
 
 
 write_ptr :: proc(f: ^File, data: rawptr, len: int) -> (n: int, err: Error) {
 write_ptr :: proc(f: ^File, data: rawptr, len: int) -> (n: int, err: Error) {
 	return write(f, ([^]byte)(data)[:len])
 	return write(f, ([^]byte)(data)[:len])

+ 15 - 15
core/os/os_darwin.odin

@@ -668,13 +668,13 @@ open :: proc(path: string, flags: int = O_RDWR, mode: int = 0) -> (Handle, Errno
 	*/
 	*/
 	if mode != 0 && !isDir {
 	if mode != 0 && !isDir {
 		err := fchmod(handle, cast(u16)mode)
 		err := fchmod(handle, cast(u16)mode)
-		if err != 0 {
+		if err != nil {
 			_unix_close(handle)
 			_unix_close(handle)
 			return INVALID_HANDLE, err
 			return INVALID_HANDLE, err
 		}
 		}
 	}
 	}
 
 
-	return handle, 0
+	return handle, nil
 }
 }
 
 
 fchmod :: proc(fd: Handle, mode: u16) -> Errno {
 fchmod :: proc(fd: Handle, mode: u16) -> Errno {
@@ -758,7 +758,7 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
 	if final_offset == -1 {
 	if final_offset == -1 {
 		return 0, Platform_Error.EPERM
 		return 0, Platform_Error.EPERM
 	}
 	}
-	return final_offset, 0
+	return final_offset, nil
 }
 }
 
 
 file_size :: proc(fd: Handle) -> (i64, Errno) {
 file_size :: proc(fd: Handle) -> (i64, Errno) {
@@ -867,7 +867,7 @@ remove :: proc(path: string) -> Errno {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 @private
 @private
@@ -921,7 +921,7 @@ _closedir :: proc(dirp: Dir) -> Errno {
 	if rc != 0 {
 	if rc != 0 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 @private
 @private
@@ -1037,7 +1037,7 @@ set_env :: proc(key, value: string) -> Errno {
 	if res < 0 {
 	if res < 0 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 unset_env :: proc(key: string) -> Errno {
 unset_env :: proc(key: string) -> Errno {
@@ -1047,7 +1047,7 @@ unset_env :: proc(key: string) -> Errno {
 	if res < 0 {
 	if res < 0 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 get_current_directory :: proc() -> string {
 get_current_directory :: proc() -> string {
@@ -1074,7 +1074,7 @@ set_current_directory :: proc(path: string) -> (err: Errno) {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 make_directory :: proc(path: string, mode: u16 = 0o775) -> Errno {
 make_directory :: proc(path: string, mode: u16 = 0o775) -> Errno {
@@ -1084,7 +1084,7 @@ make_directory :: proc(path: string, mode: u16 = 0o775) -> Errno {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 exit :: proc "contextless" (code: int) -> ! {
 exit :: proc "contextless" (code: int) -> ! {
@@ -1169,7 +1169,7 @@ connect :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Errno) {
 	if result < 0 {
 	if result < 0 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 bind :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Errno) {
 bind :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Errno) {
@@ -1177,7 +1177,7 @@ bind :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Errno) {
 	if result < 0 {
 	if result < 0 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 accept :: proc(sd: Socket, addr: ^SOCKADDR, len: rawptr) -> (Socket, Errno) {
 accept :: proc(sd: Socket, addr: ^SOCKADDR, len: rawptr) -> (Socket, Errno) {
@@ -1193,7 +1193,7 @@ listen :: proc(sd: Socket, backlog: int) -> (Errno) {
 	if result < 0 {
 	if result < 0 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	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) -> (Errno) {
@@ -1201,7 +1201,7 @@ setsockopt :: proc(sd: Socket, level: int, optname: int, optval: rawptr, optlen:
 	if result < 0 {
 	if result < 0 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	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) -> Errno {
@@ -1209,7 +1209,7 @@ getsockopt :: proc(sd: Socket, level: int, optname: int, optval: rawptr, optlen:
 	if result < 0 {
 	if result < 0 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	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, Errno) {
@@ -1249,7 +1249,7 @@ shutdown :: proc(sd: Socket, how: int) -> (Errno) {
 	if result < 0 {
 	if result < 0 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 fcntl :: proc(fd: int, cmd: int, arg: int) -> (int, Errno) {
 fcntl :: proc(fd: int, cmd: int, arg: int) -> (int, Errno) {

+ 7 - 7
core/os/os_freebsd.odin

@@ -438,7 +438,7 @@ close :: proc(fd: Handle) -> Errno {
 	if result == -1 {
 	if result == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 // If you read or write more than `INT_MAX` bytes, FreeBSD returns `EINVAL`.
 // If you read or write more than `INT_MAX` bytes, FreeBSD returns `EINVAL`.
@@ -495,7 +495,7 @@ rename :: proc(old_path, new_path: string) -> Errno {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 remove :: proc(path: string) -> Errno {
 remove :: proc(path: string) -> Errno {
@@ -505,7 +505,7 @@ remove :: proc(path: string) -> Errno {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 make_directory :: proc(path: string, mode: mode_t = 0o775) -> Errno {
 make_directory :: proc(path: string, mode: mode_t = 0o775) -> Errno {
@@ -515,7 +515,7 @@ make_directory :: proc(path: string, mode: mode_t = 0o775) -> Errno {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 remove_directory :: proc(path: string) -> Errno {
 remove_directory :: proc(path: string) -> Errno {
@@ -525,7 +525,7 @@ remove_directory :: proc(path: string) -> Errno {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 is_file_handle :: proc(fd: Handle) -> bool {
 is_file_handle :: proc(fd: Handle) -> bool {
@@ -654,7 +654,7 @@ _closedir :: proc(dirp: Dir) -> Errno {
 	if rc != 0 {
 	if rc != 0 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 @private
 @private
@@ -803,7 +803,7 @@ set_current_directory :: proc(path: string) -> (err: Errno) {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 exit :: proc "contextless" (code: int) -> ! {
 exit :: proc "contextless" (code: int) -> ! {

+ 2 - 2
core/os/os_haiku.odin

@@ -208,7 +208,7 @@ close :: proc(fd: Handle) -> Errno {
 	if result == -1 {
 	if result == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 // In practice a read/write call would probably never read/write these big buffers all at once,
 // In practice a read/write call would probably never read/write these big buffers all at once,
@@ -321,7 +321,7 @@ _closedir :: proc(dirp: Dir) -> Errno {
 	if rc != 0 {
 	if rc != 0 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 @private
 @private

+ 10 - 10
core/os/os_linux.odin

@@ -529,7 +529,7 @@ personality :: proc(persona: u64) -> (Errno) {
 	if res == -1 {
 	if res == -1 {
 		return _get_errno(res)
 		return _get_errno(res)
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 fork :: proc() -> (Pid, Errno) {
 fork :: proc() -> (Pid, Errno) {
@@ -814,7 +814,7 @@ _closedir :: proc(dirp: Dir) -> Errno {
 	if rc != 0 {
 	if rc != 0 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 @private
 @private
@@ -930,7 +930,7 @@ set_env :: proc(key, value: string) -> Errno {
 	if res < 0 {
 	if res < 0 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 unset_env :: proc(key: string) -> Errno {
 unset_env :: proc(key: string) -> Errno {
@@ -940,7 +940,7 @@ unset_env :: proc(key: string) -> Errno {
 	if res < 0 {
 	if res < 0 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 get_current_directory :: proc() -> string {
 get_current_directory :: proc() -> string {
@@ -971,7 +971,7 @@ set_current_directory :: proc(path: string) -> (err: Errno) {
 	if res < 0 {
 	if res < 0 {
 		return _get_errno(res)
 		return _get_errno(res)
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 exit :: proc "contextless" (code: int) -> ! {
 exit :: proc "contextless" (code: int) -> ! {
@@ -1042,7 +1042,7 @@ bind :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Errno) {
 	if result < 0 {
 	if result < 0 {
 		return _get_errno(result)
 		return _get_errno(result)
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 
 
@@ -1051,7 +1051,7 @@ connect :: proc(sd: Socket, addr: ^SOCKADDR, len: socklen_t) -> (Errno) {
 	if result < 0 {
 	if result < 0 {
 		return _get_errno(result)
 		return _get_errno(result)
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 accept :: proc(sd: Socket, addr: ^SOCKADDR, len: rawptr) -> (Socket, Errno) {
 accept :: proc(sd: Socket, addr: ^SOCKADDR, len: rawptr) -> (Socket, Errno) {
@@ -1067,7 +1067,7 @@ listen :: proc(sd: Socket, backlog: int) -> (Errno) {
 	if result < 0 {
 	if result < 0 {
 		return _get_errno(result)
 		return _get_errno(result)
 	}
 	}
-	return ERROR_NONE
+	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) -> (Errno) {
@@ -1075,7 +1075,7 @@ setsockopt :: proc(sd: Socket, level: int, optname: int, optval: rawptr, optlen:
 	if result < 0 {
 	if result < 0 {
 		return _get_errno(result)
 		return _get_errno(result)
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 
 
@@ -1117,7 +1117,7 @@ shutdown :: proc(sd: Socket, how: int) -> (Errno) {
 	if result < 0 {
 	if result < 0 {
 		return _get_errno(result)
 		return _get_errno(result)
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 fcntl :: proc(fd: int, cmd: int, arg: int) -> (int, Errno) {
 fcntl :: proc(fd: int, cmd: int, arg: int) -> (int, Errno) {

+ 7 - 7
core/os/os_netbsd.odin

@@ -496,7 +496,7 @@ close :: proc(fd: Handle) -> Errno {
 	if result == -1 {
 	if result == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 // We set a max of 1GB to keep alignment and to be safe.
 // We set a max of 1GB to keep alignment and to be safe.
@@ -549,7 +549,7 @@ rename :: proc(old_path, new_path: string) -> Errno {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 remove :: proc(path: string) -> Errno {
 remove :: proc(path: string) -> Errno {
@@ -559,7 +559,7 @@ remove :: proc(path: string) -> Errno {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 make_directory :: proc(path: string, mode: mode_t = 0o775) -> Errno {
 make_directory :: proc(path: string, mode: mode_t = 0o775) -> Errno {
@@ -569,7 +569,7 @@ make_directory :: proc(path: string, mode: mode_t = 0o775) -> Errno {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 remove_directory :: proc(path: string) -> Errno {
 remove_directory :: proc(path: string) -> Errno {
@@ -579,7 +579,7 @@ remove_directory :: proc(path: string) -> Errno {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 is_file_handle :: proc(fd: Handle) -> bool {
 is_file_handle :: proc(fd: Handle) -> bool {
@@ -719,7 +719,7 @@ _closedir :: proc(dirp: Dir) -> Errno {
 	if rc != 0 {
 	if rc != 0 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 @private
 @private
@@ -856,7 +856,7 @@ set_current_directory :: proc(path: string) -> (err: Errno) {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 exit :: proc "contextless" (code: int) -> ! {
 exit :: proc "contextless" (code: int) -> ! {

+ 7 - 7
core/os/os_openbsd.odin

@@ -419,7 +419,7 @@ close :: proc(fd: Handle) -> Errno {
 	if result == -1 {
 	if result == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 // If you read or write more than `SSIZE_MAX` bytes, OpenBSD returns `EINVAL`.
 // If you read or write more than `SSIZE_MAX` bytes, OpenBSD returns `EINVAL`.
@@ -476,7 +476,7 @@ rename :: proc(old_path, new_path: string) -> Errno {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 remove :: proc(path: string) -> Errno {
 remove :: proc(path: string) -> Errno {
@@ -486,7 +486,7 @@ remove :: proc(path: string) -> Errno {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 make_directory :: proc(path: string, mode: mode_t = 0o775) -> Errno {
 make_directory :: proc(path: string, mode: mode_t = 0o775) -> Errno {
@@ -496,7 +496,7 @@ make_directory :: proc(path: string, mode: mode_t = 0o775) -> Errno {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 remove_directory :: proc(path: string) -> Errno {
 remove_directory :: proc(path: string) -> Errno {
@@ -506,7 +506,7 @@ remove_directory :: proc(path: string) -> Errno {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 is_file_handle :: proc(fd: Handle) -> bool {
 is_file_handle :: proc(fd: Handle) -> bool {
@@ -638,7 +638,7 @@ _closedir :: proc(dirp: Dir) -> Errno {
 	if rc != 0 {
 	if rc != 0 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 @private
 @private
@@ -760,7 +760,7 @@ set_current_directory :: proc(path: string) -> (err: Errno) {
 	if res == -1 {
 	if res == -1 {
 		return Errno(get_last_error())
 		return Errno(get_last_error())
 	}
 	}
-	return ERROR_NONE
+	return nil
 }
 }
 
 
 exit :: proc "contextless" (code: int) -> ! {
 exit :: proc "contextless" (code: int) -> ! {

+ 1 - 1
core/os/os_wasi.odin

@@ -224,7 +224,7 @@ file_size :: proc(fd: Handle) -> (i64, Errno) {
 	if err != nil {
 	if err != nil {
 		return 0, Platform_Error(err)
 		return 0, Platform_Error(err)
 	}
 	}
-	return i64(stat.size), 0
+	return i64(stat.size), nil
 }
 }
 
 
 
 

+ 4 - 4
core/os/os_windows.odin

@@ -71,11 +71,11 @@ get_last_error :: proc "contextless" () -> Error {
 last_write_time :: proc(fd: Handle) -> (File_Time, Errno) {
 last_write_time :: proc(fd: Handle) -> (File_Time, Errno) {
 	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, Platform_Error(win32.GetLastError())
+		return 0, get_last_error()
 	}
 	}
 	lo := File_Time(file_info.ftLastWriteTime.dwLowDateTime)
 	lo := File_Time(file_info.ftLastWriteTime.dwLowDateTime)
 	hi := File_Time(file_info.ftLastWriteTime.dwHighDateTime)
 	hi := File_Time(file_info.ftLastWriteTime.dwHighDateTime)
-	return lo | hi << 32, ERROR_NONE
+	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, Errno) {
@@ -83,12 +83,12 @@ last_write_time_by_name :: proc(name: string) -> (File_Time, Errno) {
 
 
 	wide_path := win32.utf8_to_wstring(name)
 	wide_path := win32.utf8_to_wstring(name)
 	if !win32.GetFileAttributesExW(wide_path, win32.GetFileExInfoStandard, &data) {
 	if !win32.GetFileAttributesExW(wide_path, win32.GetFileExInfoStandard, &data) {
-		return 0, Platform_Error(win32.GetLastError())
+		return 0, get_last_error()
 	}
 	}
 
 
 	l := File_Time(data.ftLastWriteTime.dwLowDateTime)
 	l := File_Time(data.ftLastWriteTime.dwLowDateTime)
 	h := File_Time(data.ftLastWriteTime.dwHighDateTime)
 	h := File_Time(data.ftLastWriteTime.dwHighDateTime)
-	return l | h << 32, ERROR_NONE
+	return l | h << 32, nil
 }
 }
 
 
 
 

+ 9 - 12
core/os/stat_windows.odin

@@ -19,7 +19,7 @@ full_path_from_name :: proc(name: string, allocator := context.allocator) -> (pa
 	for {
 	for {
 		n := win32.GetFullPathNameW(raw_data(p), u32(len(buf)), raw_data(buf), nil)
 		n := win32.GetFullPathNameW(raw_data(p), u32(len(buf)), raw_data(buf), nil)
 		if n == 0 {
 		if n == 0 {
-			return "", Platform_Error(win32.GetLastError())
+			return "", get_last_error()
 		}
 		}
 		if n <= u32(len(buf)) {
 		if n <= u32(len(buf)) {
 			return win32.utf16_to_utf8(buf[:n], allocator) or_else "", ERROR_NONE
 			return win32.utf16_to_utf8(buf[:n], allocator) or_else "", ERROR_NONE
@@ -54,7 +54,7 @@ _stat :: proc(name: string, create_file_attributes: u32, allocator := context.al
 		fd: win32.WIN32_FIND_DATAW
 		fd: win32.WIN32_FIND_DATAW
 		sh := win32.FindFirstFileW(wname, &fd)
 		sh := win32.FindFirstFileW(wname, &fd)
 		if sh == win32.INVALID_HANDLE_VALUE {
 		if sh == win32.INVALID_HANDLE_VALUE {
-			e = Platform_Error(win32.GetLastError())
+			e = get_last_error()
 			return
 			return
 		}
 		}
 		win32.FindClose(sh)
 		win32.FindClose(sh)
@@ -64,7 +64,7 @@ _stat :: proc(name: string, create_file_attributes: u32, allocator := context.al
 
 
 	h := win32.CreateFileW(wname, 0, 0, nil, win32.OPEN_EXISTING, create_file_attributes, nil)
 	h := win32.CreateFileW(wname, 0, 0, nil, win32.OPEN_EXISTING, create_file_attributes, nil)
 	if h == win32.INVALID_HANDLE_VALUE {
 	if h == win32.INVALID_HANDLE_VALUE {
-		e = Platform_Error(win32.GetLastError())
+		e = get_last_error()
 		return
 		return
 	}
 	}
 	defer win32.CloseHandle(h)
 	defer win32.CloseHandle(h)
@@ -134,13 +134,10 @@ cleanpath_strip_prefix :: proc(buf: []u16) -> []u16 {
 }
 }
 
 
 @(private)
 @(private)
-cleanpath_from_handle :: proc(fd: Handle) -> (string, Errno) {
+cleanpath_from_handle :: proc(fd: Handle) -> (s: string, err: Errno) {
 	runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == context.allocator)
 	runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == context.allocator)
-	buf, err := cleanpath_from_handle_u16(fd, context.temp_allocator)
-	if err != 0 {
-		return "", err
-	}
-	return win32.utf16_to_utf8(buf, context.allocator) or_else "", err
+	buf := cleanpath_from_handle_u16(fd, context.temp_allocator) or_return
+	return win32.utf16_to_utf8(buf, context.allocator)
 }
 }
 @(private)
 @(private)
 cleanpath_from_handle_u16 :: proc(fd: Handle, allocator: runtime.Allocator) -> ([]u16, Errno) {
 cleanpath_from_handle_u16 :: proc(fd: Handle, allocator: runtime.Allocator) -> ([]u16, Errno) {
@@ -151,7 +148,7 @@ cleanpath_from_handle_u16 :: proc(fd: Handle, allocator: runtime.Allocator) -> (
 
 
 	n := win32.GetFinalPathNameByHandleW(h, nil, 0, 0)
 	n := win32.GetFinalPathNameByHandleW(h, nil, 0, 0)
 	if n == 0 {
 	if n == 0 {
-		return nil, Platform_Error(win32.GetLastError())
+		return nil, get_last_error()
 	}
 	}
 	buf := make([]u16, max(n, win32.DWORD(260))+1, allocator)
 	buf := make([]u16, max(n, win32.DWORD(260))+1, allocator)
 	buf_len := win32.GetFinalPathNameByHandleW(h, raw_data(buf), n, 0)
 	buf_len := win32.GetFinalPathNameByHandleW(h, raw_data(buf), n, 0)
@@ -273,14 +270,14 @@ file_info_from_win32_find_data :: proc(d: ^win32.WIN32_FIND_DATAW, name: string)
 file_info_from_get_file_information_by_handle :: proc(path: string, h: win32.HANDLE) -> (File_Info, Errno) {
 file_info_from_get_file_information_by_handle :: proc(path: string, h: win32.HANDLE) -> (File_Info, Errno) {
 	d: win32.BY_HANDLE_FILE_INFORMATION
 	d: win32.BY_HANDLE_FILE_INFORMATION
 	if !win32.GetFileInformationByHandle(h, &d) {
 	if !win32.GetFileInformationByHandle(h, &d) {
-		err := Platform_Error(win32.GetLastError())
+		err := get_last_error()
 		return {}, err
 		return {}, err
 
 
 	}
 	}
 
 
 	ti: win32.FILE_ATTRIBUTE_TAG_INFO
 	ti: win32.FILE_ATTRIBUTE_TAG_INFO
 	if !win32.GetFileInformationByHandleEx(h, .FileAttributeTagInfo, &ti, size_of(ti)) {
 	if !win32.GetFileInformationByHandleEx(h, .FileAttributeTagInfo, &ti, size_of(ti)) {
-		err := Platform_Error(win32.GetLastError())
+		err := get_last_error()
 		if err != ERROR_INVALID_PARAMETER {
 		if err != ERROR_INVALID_PARAMETER {
 			return {}, err
 			return {}, err
 		}
 		}

+ 5 - 5
core/os/stream.odin

@@ -27,7 +27,7 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
 	case .Read:
 	case .Read:
 		n_int, os_err = read(fd, p)
 		n_int, os_err = read(fd, p)
 		n = i64(n_int)
 		n = i64(n_int)
-		if n == 0 && os_err == 0 {
+		if n == 0 && os_err == nil {
 			err = .EOF
 			err = .EOF
 		}
 		}
 
 
@@ -35,21 +35,21 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
 		when !(ODIN_OS == .FreeBSD || ODIN_OS == .OpenBSD || ODIN_OS == .NetBSD || ODIN_OS == .Haiku) {
 		when !(ODIN_OS == .FreeBSD || ODIN_OS == .OpenBSD || ODIN_OS == .NetBSD || ODIN_OS == .Haiku) {
 			n_int, os_err = read_at(fd, p, offset)
 			n_int, os_err = read_at(fd, p, offset)
 			n = i64(n_int)
 			n = i64(n_int)
-			if n == 0 && os_err == 0 {
+			if n == 0 && os_err == nil {
 				err = .EOF
 				err = .EOF
 			}
 			}
 		}
 		}
 	case .Write:
 	case .Write:
 		n_int, os_err = write(fd, p)
 		n_int, os_err = write(fd, p)
 		n = i64(n_int)
 		n = i64(n_int)
-		if n == 0 && os_err == 0 {
+		if n == 0 && os_err == nil {
 			err = .EOF
 			err = .EOF
 		}
 		}
 	case .Write_At:
 	case .Write_At:
 		when !(ODIN_OS == .FreeBSD || ODIN_OS == .OpenBSD || ODIN_OS == .NetBSD || ODIN_OS == .Haiku) {
 		when !(ODIN_OS == .FreeBSD || ODIN_OS == .OpenBSD || ODIN_OS == .NetBSD || ODIN_OS == .Haiku) {
 			n_int, os_err = write_at(fd, p, offset)
 			n_int, os_err = write_at(fd, p, offset)
 			n = i64(n_int)
 			n = i64(n_int)
-			if n == 0 && os_err == 0 {
+			if n == 0 && os_err == nil {
 				err = .EOF
 				err = .EOF
 			}
 			}
 		}
 		}
@@ -67,7 +67,7 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
 		}
 		}
 	}
 	}
 
 
-	if err == nil && os_err != 0 {
+	if err == nil && os_err != nil {
 		when ODIN_OS == .Windows {
 		when ODIN_OS == .Windows {
 			if os_err == ERROR_HANDLE_EOF {
 			if os_err == ERROR_HANDLE_EOF {
 				return n, .EOF
 				return n, .EOF