Ver Fonte

Move errors to where appropriate

gingerBill há 1 ano atrás
pai
commit
e8d26c5797

+ 1 - 1
core/os/dir_windows.odin

@@ -58,7 +58,7 @@ read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []F
 
 	dir_fi, _ := file_info_from_get_file_information_by_handle("", h)
 	if !dir_fi.is_dir {
-		return nil, ERROR_FILE_IS_NOT_DIR
+		return nil, .Not_Dir
 	}
 
 	n := n

+ 5 - 0
core/os/errors.odin

@@ -32,6 +32,9 @@ General_Error :: enum u32 {
 	Pattern_Has_Separator,
 
 	Unsupported,
+
+	File_Is_Pipe,
+	Not_Dir,
 }
 
 
@@ -77,6 +80,8 @@ error_string :: proc "contextless" (ferr: Error) -> string {
 		case .Invalid_Callback:  return "invalid callback"
 		case .Unsupported:       return "unsupported"
 		case .Pattern_Has_Separator: return "pattern has separator"
+		case .File_Is_Pipe:      return "file is pipe"
+		case .Not_Dir:           return "file is not directory"
 		}
 	case io.Error:
 		switch e {

+ 3 - 3
core/os/file_windows.odin

@@ -195,7 +195,7 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Error) {
 	lo := i32(offset)
 	ft := win32.GetFileType(win32.HANDLE(fd))
 	if ft == win32.FILE_TYPE_PIPE {
-		return 0, ERROR_FILE_IS_PIPE
+		return 0, .File_Is_Pipe
 	}
 
 	dw_ptr := win32.SetFilePointer(win32.HANDLE(fd), lo, &hi, w)
@@ -278,7 +278,7 @@ will read from the location twice on *nix, and from two different locations on W
 */
 read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Error) {
 	if offset < 0 {
-		return 0, ERROR_NEGATIVE_OFFSET
+		return 0, .Invalid_Offset
 	}
 
 	b, offset := data, offset
@@ -310,7 +310,7 @@ will write to the location twice on *nix, and to two different locations on Wind
 */
 write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Error) {
 	if offset < 0 {
-		return 0, ERROR_NEGATIVE_OFFSET
+		return 0, .Invalid_Offset
 	}
 
 	b, offset := data, offset

+ 2 - 4
core/os/os_js.odin

@@ -241,10 +241,8 @@ ERROR_PRIVILEGE_NOT_HELD  :: Platform_Error.PRIVILEGE_NOT_HELD
 WSAEACCES                 :: Platform_Error.WSAEACCES
 WSAECONNRESET             :: Platform_Error.WSAECONNRESET
 
-// Windows reserves errors >= 1<<29 for application use
-ERROR_FILE_IS_PIPE        :: Platform_Error.FILE_IS_PIPE
-ERROR_FILE_IS_NOT_DIR     :: Platform_Error.FILE_IS_NOT_DIR
-ERROR_NEGATIVE_OFFSET     :: Platform_Error.NEGATIVE_OFFSET
+ERROR_FILE_IS_PIPE        :: General_Error.File_Is_Pipe
+ERROR_FILE_IS_NOT_DIR     :: General_Error.Not_Dir
 
 // "Argv" arguments converted to Odin strings
 args := _alloc_command_line_arguments()

+ 2 - 4
core/os/os_windows.odin

@@ -54,10 +54,8 @@ ERROR_PRIVILEGE_NOT_HELD  :: _Platform_Error(1314)
 WSAEACCES                 :: _Platform_Error(10013)
 WSAECONNRESET             :: _Platform_Error(10054)
 
-// Windows reserves errors >= 1<<29 for application use
-ERROR_FILE_IS_PIPE        :: _Platform_Error(1<<29 + 0)
-ERROR_FILE_IS_NOT_DIR     :: _Platform_Error(1<<29 + 1)
-ERROR_NEGATIVE_OFFSET     :: _Platform_Error(1<<29 + 2)
+ERROR_FILE_IS_PIPE        :: General_Error.File_Is_Pipe
+ERROR_FILE_IS_NOT_DIR     :: General_Error.Not_Dir
 
 // "Argv" arguments converted to Odin strings
 args := _alloc_command_line_arguments()