Remove core:os dependency for runtime.os_write on linux

This commit is contained in:
gingerBill
2024-01-28 22:05:13 +00:00
parent 9e7cc8cf93
commit 9be9f0bb2c
2 changed files with 23 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
//+build !darwin
//+build !linux
//+build !freestanding
//+build !js
//+build !wasi

View File

@@ -0,0 +1,22 @@
//+private
package runtime
import "base:intrinsics"
_os_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
when ODIN_ARCH == .amd64 {
SYS_write :: uintptr(1)
} else when ODIN_ARCH == .arm64 {
SYS_write :: uintptr(64)
} else when ODIN_ARCH == .i386 {
SYS_write :: uintptr(4)
} else when ODIN_ARCH == .arm32 {
SYS_write :: uintptr(4)
}
ret := int(intrinsics.syscall(SYS_write, uintptr(stderr), uintptr(raw_data(data)), uintptr(len(data))))
if ret < 0 && ret > -4096 {
return 0, _OS_Errno(-ret)
}
return ret, 0
}