Report Invalid_Whence on some os platforms

- Move `Seek`-related checks into OS-specific files for granularity.

Platforms:
- Darwin
- FreeBSD
- Haiku
- Linux
- NetBSD
- OpenBSD
This commit is contained in:
Feoramund
2024-08-28 19:53:20 +02:00
committed by Laytan
parent 0243647e15
commit 6aedb2695a
7 changed files with 73 additions and 14 deletions
+12 -1
View File
@@ -653,9 +653,20 @@ write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (int, Error) {
}
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Error) {
switch whence {
case SEEK_SET, SEEK_CUR, SEEK_END:
break
case:
return 0, .Invalid_Whence
}
res := unix.sys_lseek(int(fd), offset, whence)
if res < 0 {
return -1, _get_errno(int(res))
errno := _get_errno(int(res))
switch errno {
case .EINVAL:
return 0, .Invalid_Offset
}
return 0, errno
}
return i64(res), nil
}