mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-08 14:03:14 +00:00
Remove core:os dependency completely from base:runtime
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
//+build !darwin
|
||||
//+build !linux
|
||||
//+build !freestanding
|
||||
//+build !js
|
||||
//+build !wasi
|
||||
//+build !windows
|
||||
//+private
|
||||
package runtime
|
||||
|
||||
import "core:os"
|
||||
|
||||
// TODO(bill): reimplement `os.write` so that it does not rely on package os
|
||||
// NOTE: Use os_specific_linux.odin, os_specific_darwin.odin, etc
|
||||
_os_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
|
||||
context = default_context()
|
||||
n, err := os.write(os.stderr, data)
|
||||
return int(n), _OS_Errno(err)
|
||||
}
|
||||
21
base/runtime/os_specific_bsd.odin
Normal file
21
base/runtime/os_specific_bsd.odin
Normal file
@@ -0,0 +1,21 @@
|
||||
//+build freebsd, openbsd
|
||||
//+private
|
||||
package runtime
|
||||
|
||||
foreign import libc "system:c"
|
||||
|
||||
foreign libc {
|
||||
@(link_name="write")
|
||||
_unix_write :: proc(fd: uintptr, buf: rawptr, size: int) -> int ---
|
||||
|
||||
__error :: proc() -> ^i32 ---
|
||||
}
|
||||
|
||||
_os_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
|
||||
ret := _unix_write(2, raw_data(data), len(data))
|
||||
if ret < len(data) {
|
||||
err := __error()
|
||||
return int(ret), _OS_Errno(err^ if err != nil else 0)
|
||||
}
|
||||
return int(ret), 0
|
||||
}
|
||||
@@ -255,7 +255,7 @@ W_OK :: 2 // Test for write permission
|
||||
R_OK :: 4 // Test for read permission
|
||||
|
||||
foreign libc {
|
||||
@(link_name="__error") __errno_location :: proc() -> ^int ---
|
||||
@(link_name="__error") __errno_location :: proc() -> ^c.int ---
|
||||
|
||||
@(link_name="open") _unix_open :: proc(path: cstring, flags: c.int, mode: c.int) -> Handle ---
|
||||
@(link_name="close") _unix_close :: proc(fd: Handle) -> c.int ---
|
||||
|
||||
@@ -246,7 +246,7 @@ AT_REMOVEDIR :: 0x08
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign libc {
|
||||
@(link_name="__errno") __errno :: proc() -> ^int ---
|
||||
@(link_name="__error") __error :: proc() -> ^c.int ---
|
||||
|
||||
@(link_name="fork") _unix_fork :: proc() -> pid_t ---
|
||||
@(link_name="getthrid") _unix_getthrid :: proc() -> int ---
|
||||
@@ -296,7 +296,7 @@ is_path_separator :: proc(r: rune) -> bool {
|
||||
}
|
||||
|
||||
get_last_error :: proc "contextless" () -> int {
|
||||
return __errno()^
|
||||
return __error()^
|
||||
}
|
||||
|
||||
fork :: proc() -> (Pid, Errno) {
|
||||
|
||||
Reference in New Issue
Block a user