mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-29 01:33:56 +00:00
Fix broken cases of Seek usage in _file_stream_proc
Handles `EINVAL`, among other fixes.
This commit is contained in:
@@ -192,6 +192,8 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Error) {
|
||||
case 0: w = win32.FILE_BEGIN
|
||||
case 1: w = win32.FILE_CURRENT
|
||||
case 2: w = win32.FILE_END
|
||||
case:
|
||||
return 0, .Invalid_Whence
|
||||
}
|
||||
hi := i32(offset>>32)
|
||||
lo := i32(offset)
|
||||
|
||||
@@ -43,6 +43,7 @@ ERROR_BUFFER_OVERFLOW :: _Platform_Error(111)
|
||||
ERROR_INSUFFICIENT_BUFFER :: _Platform_Error(122)
|
||||
ERROR_MOD_NOT_FOUND :: _Platform_Error(126)
|
||||
ERROR_PROC_NOT_FOUND :: _Platform_Error(127)
|
||||
ERROR_NEGATIVE_SEEK :: _Platform_Error(131)
|
||||
ERROR_DIR_NOT_EMPTY :: _Platform_Error(145)
|
||||
ERROR_ALREADY_EXISTS :: _Platform_Error(183)
|
||||
ERROR_ENVVAR_NOT_FOUND :: _Platform_Error(203)
|
||||
@@ -91,6 +92,9 @@ get_last_error :: proc "contextless" () -> Error {
|
||||
case win32.ERROR_INVALID_HANDLE:
|
||||
return .Invalid_File
|
||||
|
||||
case win32.ERROR_NEGATIVE_SEEK:
|
||||
return .Invalid_Offset
|
||||
|
||||
case
|
||||
win32.ERROR_BAD_ARGUMENTS,
|
||||
win32.ERROR_INVALID_PARAMETER,
|
||||
|
||||
@@ -47,6 +47,14 @@ _file_stream_proc :: proc(stream_data: rawptr, mode: io.Stream_Mode, p: []byte,
|
||||
}
|
||||
case .Seek:
|
||||
n, os_err = seek(fd, offset, int(whence))
|
||||
if os_err != nil {
|
||||
switch whence {
|
||||
case .Start, .Current, .End:
|
||||
return 0, .Invalid_Offset
|
||||
case:
|
||||
return 0, .Invalid_Whence
|
||||
}
|
||||
}
|
||||
case .Size:
|
||||
n, os_err = file_size(fd)
|
||||
case .Destroy:
|
||||
|
||||
@@ -213,6 +213,7 @@ ERROR_BROKEN_PIPE : DWORD : 109
|
||||
ERROR_CALL_NOT_IMPLEMENTED : DWORD : 120
|
||||
ERROR_INSUFFICIENT_BUFFER : DWORD : 122
|
||||
ERROR_INVALID_NAME : DWORD : 123
|
||||
ERROR_NEGATIVE_SEEK : DWORD : 131
|
||||
ERROR_BAD_ARGUMENTS : DWORD : 160
|
||||
ERROR_LOCK_FAILED : DWORD : 167
|
||||
ERROR_ALREADY_EXISTS : DWORD : 183
|
||||
|
||||
Reference in New Issue
Block a user