diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2025-11-14 11:08:24 +0000 |
|---|---|---|
| committer | gingerBill <gingerBill@users.noreply.github.com> | 2025-11-14 11:08:24 +0000 |
| commit | 51536fecf4859d61d2a0a786eb33ac4f2dc4fb73 (patch) | |
| tree | bb974080bbe46c1fba72b63de0c9c395d32860ac | |
| parent | bd21b2cf49cc27515df911bc57397f8833035c73 (diff) | |
Move some of the os&os2 errors into `io.Error`; Rename Empty to Unsupported
| -rw-r--r-- | core/io/io.odin | 40 | ||||
| -rw-r--r-- | core/os/errors.odin | 18 | ||||
| -rw-r--r-- | core/os/os2/errors.odin | 18 |
3 files changed, 37 insertions, 39 deletions
diff --git a/core/io/io.odin b/core/io/io.odin index 2c9b4379f..9fae30946 100644 --- a/core/io/io.odin +++ b/core/io/io.odin @@ -38,8 +38,11 @@ Error :: enum i32 { // This is usually a sign of a broken `io.Reader` implementation No_Progress, + // Invalid whence argument Invalid_Whence, + // Invalid offset Invalid_Offset, + // Invalid "unread" operation Invalid_Unread, Negative_Read, @@ -50,8 +53,19 @@ Error :: enum i32 { // Unknown means that an error has occurred but cannot be categorized Unknown, - // Empty is returned when a procedure has not been implemented for an io.Stream - Empty = -1, + // Indicates that an attempt to retrieve a Stream's size was made, but the + // stream doesn't have a size. + No_Size, + + Permission_Denied, + + // Stream cannot be used since it has been Closed + Closed, + + // Unsupported is returned when a procedure has not been implemented for an io.Stream + Unsupported = -1, + + Empty = Unsupported, } Stream_Mode :: enum { @@ -102,7 +116,7 @@ destroy :: proc(s: Stream) -> (err: Error) { if s.procedure != nil { _, err = s.procedure(s.data, .Destroy, nil, 0, nil) } else { - err = .Empty + err = .Unsupported } return } @@ -138,7 +152,7 @@ read :: proc(s: Reader, p: []byte, n_read: ^int = nil) -> (n: int, err: Error) { n = int(n64) if n_read != nil { n_read^ += n } } else { - err = .Empty + err = .Unsupported } return } @@ -151,7 +165,7 @@ write :: proc(s: Writer, p: []byte, n_written: ^int = nil) -> (n: int, err: Erro n = int(n64) if n_written != nil { n_written^ += n } } else { - err = .Empty + err = .Unsupported } return } @@ -167,7 +181,7 @@ seek :: proc(s: Seeker, offset: i64, whence: Seek_From) -> (n: i64, err: Error) if s.procedure != nil { n, err = s.procedure(s.data, .Seek, nil, offset, whence) } else { - err = .Empty + err = .Unsupported } return } @@ -192,7 +206,7 @@ flush :: proc(s: Flusher) -> (err: Error) { size :: proc(s: Stream) -> (n: i64, err: Error) { if s.procedure != nil { n, err = s.procedure(s.data, .Size, nil, 0, nil) - if err == .Empty { + if err == .Unsupported { n = 0 curr := seek(s, 0, .Current) or_return end := seek(s, 0, .End) or_return @@ -200,7 +214,7 @@ size :: proc(s: Stream) -> (n: i64, err: Error) { n = end } } else { - err = .Empty + err = .Unsupported } return } @@ -217,7 +231,7 @@ read_at :: proc(r: Reader_At, p: []byte, offset: i64, n_read: ^int = nil) -> (n: if r.procedure != nil { n64: i64 n64, err = r.procedure(r.data, .Read_At, p, offset, nil) - if err != .Empty { + if err != .Unsupported { n = int(n64) } else { curr := seek(r, offset, .Current) or_return @@ -229,7 +243,7 @@ read_at :: proc(r: Reader_At, p: []byte, offset: i64, n_read: ^int = nil) -> (n: } if n_read != nil { n_read^ += n } } else { - err = .Empty + err = .Unsupported } return } @@ -243,7 +257,7 @@ write_at :: proc(w: Writer_At, p: []byte, offset: i64, n_written: ^int = nil) -> if w.procedure != nil { n64: i64 n64, err = w.procedure(w.data, .Write_At, p, offset, nil) - if err != .Empty { + if err != .Unsupported { n = int(n64) } else { curr := seek(w, offset, .Current) or_return @@ -255,7 +269,7 @@ write_at :: proc(w: Writer_At, p: []byte, offset: i64, n_written: ^int = nil) -> } if n_written != nil { n_written^ += n } } else { - err = .Empty + err = .Unsupported } return } @@ -440,7 +454,7 @@ copy_n :: proc(dst: Writer, src: Reader, n: i64) -> (written: i64, err: Error) { @(private) _copy_buffer :: proc(dst: Writer, src: Reader, buf: []byte) -> (written: i64, err: Error) { if dst.procedure == nil || src.procedure == nil { - return 0, .Empty + return 0, .Unsupported } buf := buf if buf == nil { diff --git a/core/os/errors.odin b/core/os/errors.odin index bf4cf27ff..fcf70ec74 100644 --- a/core/os/errors.odin +++ b/core/os/errors.odin @@ -11,19 +11,13 @@ Platform_Error :: _Platform_Error General_Error :: enum u32 { None, - Permission_Denied, Exist, Not_Exist, - Closed, Timeout, Broken_Pipe, - // Indicates that an attempt to retrieve a file's size was made, but the - // file doesn't have a size. - No_Size, - Invalid_File, Invalid_Dir, Invalid_Path, @@ -31,8 +25,6 @@ General_Error :: enum u32 { Pattern_Has_Separator, - Unsupported, - File_Is_Pipe, Not_Dir, @@ -70,18 +62,14 @@ error_string :: proc "contextless" (ferr: Error) -> string { case General_Error: switch e { case .None: return "" - case .Permission_Denied: return "permission denied" case .Exist: return "file already exists" case .Not_Exist: return "file does not exist" - case .Closed: return "file already closed" case .Timeout: return "i/o timeout" case .Broken_Pipe: return "Broken pipe" - case .No_Size: return "file has no definite size" case .Invalid_File: return "invalid file" case .Invalid_Dir: return "invalid directory" case .Invalid_Path: return "invalid path" 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" @@ -103,7 +91,11 @@ error_string :: proc "contextless" (ferr: Error) -> string { case .Negative_Write: return "negative write" case .Negative_Count: return "negative count" case .Buffer_Full: return "buffer full" - case .Unknown, .Empty: // + case .Permission_Denied: return "permission denied" + case .Closed: return "file already closed" + case .No_Size: return "file has no definite size" + case .Unsupported: return "unsupported" + case .Unknown: // } case runtime.Allocator_Error: switch e { diff --git a/core/os/os2/errors.odin b/core/os/os2/errors.odin index 077697c0d..2d959e182 100644 --- a/core/os/os2/errors.odin +++ b/core/os/os2/errors.odin @@ -10,19 +10,13 @@ import "base:runtime" General_Error :: enum u32 { None, - Permission_Denied, Exist, Not_Exist, - Closed, Timeout, Broken_Pipe, - // Indicates that an attempt to retrieve a file's size was made, but the - // file doesn't have a size. - No_Size, - Invalid_File, Invalid_Dir, Invalid_Path, @@ -33,8 +27,6 @@ General_Error :: enum u32 { No_HOME_Variable, Env_Var_Not_Found, - - Unsupported, } // A platform specific error @@ -72,19 +64,15 @@ error_string :: proc(ferr: Error) -> string { case General_Error: switch e { case .None: return "" - case .Permission_Denied: return "permission denied" case .Exist: return "file already exists" case .Not_Exist: return "file does not exist" - case .Closed: return "file already closed" case .Timeout: return "i/o timeout" case .Broken_Pipe: return "Broken pipe" - case .No_Size: return "file has no definite size" case .Invalid_File: return "invalid file" case .Invalid_Dir: return "invalid directory" case .Invalid_Path: return "invalid path" case .Invalid_Callback: return "invalid callback" case .Invalid_Command: return "invalid command" - case .Unsupported: return "unsupported" case .Pattern_Has_Separator: return "pattern has separator" case .No_HOME_Variable: return "no $HOME variable" case .Env_Var_Not_Found: return "environment variable not found" @@ -105,7 +93,11 @@ error_string :: proc(ferr: Error) -> string { case .Negative_Write: return "negative write" case .Negative_Count: return "negative count" case .Buffer_Full: return "buffer full" - case .Unknown, .Empty: // + case .Permission_Denied: return "permission denied" + case .Closed: return "file already closed" + case .No_Size: return "file has no definite size" + case .Unsupported: return "unsupported" + case .Unknown: // } case runtime.Allocator_Error: switch e { |