mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-18 04:20:28 +00:00
Merge pull request #5928 from odin-lang/bill/io-error-changes
Move some OS General_Error values to io.Error
This commit is contained in:
@@ -38,5 +38,5 @@ _read_writer_procedure := proc(stream_data: rawptr, mode: io.Stream_Mode, p: []b
|
||||
case .Query:
|
||||
return io.query_utility({.Flush, .Read, .Write, .Query})
|
||||
}
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
@@ -347,7 +347,7 @@ _reader_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, offse
|
||||
case .Query:
|
||||
return io.query_utility({.Read, .Destroy, .Query})
|
||||
}
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -249,5 +249,5 @@ _writer_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, offse
|
||||
case .Query:
|
||||
return io.query_utility({.Flush, .Write, .Destroy, .Query})
|
||||
}
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
|
||||
@@ -434,5 +434,5 @@ _buffer_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, offse
|
||||
case .Query:
|
||||
return io.query_utility({.Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Destroy, .Query})
|
||||
}
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
|
||||
@@ -160,6 +160,6 @@ _reader_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, offse
|
||||
case .Query:
|
||||
return io.query_utility({.Read, .Read_At, .Seek, .Size, .Query})
|
||||
}
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
|
||||
|
||||
@@ -390,7 +390,7 @@ to_stream :: proc(file: ^FILE) -> io.Stream {
|
||||
}
|
||||
|
||||
case .Destroy:
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
|
||||
case .Query:
|
||||
return io.query_utility({ .Close, .Flush, .Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Query })
|
||||
|
||||
@@ -297,7 +297,7 @@ peek_data_from_stream :: #force_inline proc(z: ^Context_Stream_Input, $T: typeid
|
||||
curr := z.input->impl_seek(0, .Current) or_return
|
||||
r, e1 := io.to_reader_at(z.input)
|
||||
if !e1 {
|
||||
return T{}, .Empty
|
||||
return T{}, .Unsupported
|
||||
}
|
||||
when size <= 128 {
|
||||
b: [size]u8
|
||||
@@ -306,7 +306,7 @@ peek_data_from_stream :: #force_inline proc(z: ^Context_Stream_Input, $T: typeid
|
||||
}
|
||||
_, e2 := io.read_at(r, b[:], curr)
|
||||
if e2 != .None {
|
||||
return T{}, .Empty
|
||||
return T{}, .Unsupported
|
||||
}
|
||||
|
||||
res = (^T)(&b[0])^
|
||||
@@ -324,7 +324,7 @@ peek_data_at_offset_from_stream :: #force_inline proc(z: ^Context_Stream_Input,
|
||||
|
||||
r, e3 := io.to_reader_at(z.input)
|
||||
if !e3 {
|
||||
return T{}, .Empty
|
||||
return T{}, .Unsupported
|
||||
}
|
||||
when size <= 128 {
|
||||
b: [size]u8
|
||||
@@ -333,7 +333,7 @@ peek_data_at_offset_from_stream :: #force_inline proc(z: ^Context_Stream_Input,
|
||||
}
|
||||
_, e4 := io.read_at(r, b[:], pos)
|
||||
if e4 != .None {
|
||||
return T{}, .Empty
|
||||
return T{}, .Unsupported
|
||||
}
|
||||
|
||||
// Return read head to original position.
|
||||
|
||||
@@ -19,7 +19,7 @@ write_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
|
||||
write(fd, p)
|
||||
return i64(len(p)), nil
|
||||
}
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
|
||||
@(private="file")
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -8,7 +8,7 @@ _multi_reader_proc :: proc(stream_data: rawptr, mode: Stream_Mode, p: []byte, of
|
||||
if mode == .Query {
|
||||
return query_utility({.Read, .Query})
|
||||
} else if mode != .Read {
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
mr := (^Multi_Reader)(stream_data)
|
||||
for len(mr.readers) > 0 {
|
||||
@@ -61,7 +61,7 @@ _multi_writer_proc :: proc(stream_data: rawptr, mode: Stream_Mode, p: []byte, of
|
||||
if mode == .Query {
|
||||
return query_utility({.Write, .Query})
|
||||
} else if mode != .Write {
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
mw := (^Multi_Writer)(stream_data)
|
||||
for w in mw.writers {
|
||||
|
||||
@@ -354,7 +354,7 @@ _tee_reader_proc :: proc(stream_data: rawptr, mode: Stream_Mode, p: []byte, offs
|
||||
case .Query:
|
||||
return query_utility({.Read, .Query})
|
||||
}
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
|
||||
// tee_reader_init returns a Reader that writes to 'w' what it reads from 'r'
|
||||
@@ -404,7 +404,7 @@ _limited_reader_proc :: proc(stream_data: rawptr, mode: Stream_Mode, p: []byte,
|
||||
case .Query:
|
||||
return query_utility({.Read, .Query})
|
||||
}
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
|
||||
limited_reader_init :: proc(l: ^Limited_Reader, r: Reader, n: i64) -> Reader {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -515,7 +515,7 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
|
||||
case .Query:
|
||||
return io.query_utility({.Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Flush, .Close, .Destroy, .Query})
|
||||
}
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
|
||||
|
||||
@@ -559,6 +559,6 @@ _file_stream_buffered_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p:
|
||||
case .Query:
|
||||
return io.query_utility({.Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Flush, .Close, .Destroy, .Query})
|
||||
}
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
|
||||
|
||||
@@ -502,6 +502,6 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
|
||||
return io.query_utility({.Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Flush, .Close, .Destroy, .Query})
|
||||
|
||||
case:
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
}
|
||||
|
||||
@@ -557,6 +557,6 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
|
||||
return io.query_utility({.Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Flush, .Close, .Destroy, .Query})
|
||||
|
||||
case:
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
}
|
||||
|
||||
@@ -866,7 +866,7 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
|
||||
case .Query:
|
||||
return io.query_utility({.Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Flush, .Close, .Destroy, .Query})
|
||||
}
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
|
||||
case .Size:
|
||||
n, os_err = file_size(fd)
|
||||
case .Destroy:
|
||||
err = .Empty
|
||||
err = .Unsupported
|
||||
case .Query:
|
||||
return io.query_utility({.Close, .Flush, .Read, .Read_At, .Write, .Write_At, .Seek, .Size, .Query})
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ _builder_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byt
|
||||
case .Query:
|
||||
return io.query_utility({.Write, .Size, .Destroy, .Query})
|
||||
}
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -310,5 +310,5 @@ _reader_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte, offse
|
||||
case .Query:
|
||||
return io.query_utility({.Size, .Read, .Read_At, .Seek, .Query})
|
||||
}
|
||||
return 0, .Empty
|
||||
return 0, .Unsupported
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user