Browse Source

Report `Invalid_Whence` in `os2` Linux seek

Feoramund 11 months ago
parent
commit
3ec4db212b
1 changed files with 14 additions and 2 deletions
  1. 14 2
      core/os/os2/file_linux.odin

+ 14 - 2
core/os/os2/file_linux.odin

@@ -170,11 +170,23 @@ _name :: proc(f: ^File) -> string {
 }
 }
 
 
 _seek :: proc(f: ^File_Impl, offset: i64, whence: io.Seek_From) -> (ret: i64, err: Error) {
 _seek :: proc(f: ^File_Impl, offset: i64, whence: io.Seek_From) -> (ret: i64, err: Error) {
+	// We have to handle this here, because Linux returns EINVAL for both
+	// invalid offsets and invalid whences.
+	switch whence {
+	case .Start, .Current, .End:
+		break
+	case:
+		return 0, .Invalid_Whence
+	}
 	n, errno := linux.lseek(f.fd, offset, linux.Seek_Whence(whence))
 	n, errno := linux.lseek(f.fd, offset, linux.Seek_Whence(whence))
-	if errno != .NONE {
+	#partial switch errno {
+	case .EINVAL:
+		return 0, .Invalid_Offset
+	case .NONE:
+		return n, nil
+	case:
 		return -1, _get_platform_error(errno)
 		return -1, _get_platform_error(errno)
 	}
 	}
-	return n, nil
 }
 }
 
 
 _read :: proc(f: ^File_Impl, p: []byte) -> (i64, Error) {
 _read :: proc(f: ^File_Impl, p: []byte) -> (i64, Error) {