sys/posix: impl rest of linux, impl some of Windows

This commit is contained in:
Laytan Laats
2024-12-01 11:54:51 +11:00
committed by flysand7
parent 879771fe32
commit 49ddbd9b99
63 changed files with 1237 additions and 789 deletions
+1 -78
View File
@@ -1,9 +1,9 @@
#+build linux, darwin, netbsd, openbsd, freebsd
package posix
import "base:intrinsics"
import "core:c"
import "core:c/libc"
when ODIN_OS == .Darwin {
foreign import lib "system:System.framework"
@@ -11,56 +11,6 @@ when ODIN_OS == .Darwin {
foreign import lib "system:c"
}
// stdlib.h - standard library definitions
atof :: libc.atof
atoi :: libc.atoi
atol :: libc.atol
atoll :: libc.atoll
strtod :: libc.strtod
strtof :: libc.strtof
strtol :: libc.strtol
strtoll :: libc.strtoll
strtoul :: libc.strtoul
strtoull :: libc.strtoull
rand :: libc.rand
srand :: libc.srand
calloc :: libc.calloc
malloc :: libc.malloc
realloc :: libc.realloc
abort :: libc.abort
atexit :: libc.atexit
at_quick_exit :: libc.at_quick_exit
exit :: libc.exit
_Exit :: libc._Exit
getenv :: libc.getenv
quick_exit :: libc.quick_exit
system :: libc.system
bsearch :: libc.bsearch
qsort :: libc.qsort
abs :: libc.abs
labs :: libc.labs
llabs :: libc.llabs
div :: libc.div
ldiv :: libc.ldiv
lldiv :: libc.lldiv
mblen :: libc.mblen
mbtowc :: libc.mbtowc
wctomb :: libc.wctomb
mbstowcs :: libc.mbstowcs
wcstombs :: libc.wcstombs
free :: #force_inline proc(ptr: $T) where intrinsics.type_is_pointer(T) || intrinsics.type_is_multi_pointer(T) || T == cstring {
libc.free(rawptr(ptr))
}
foreign lib {
/*
Takes a pointer to a radix-64 representation, in which the first digit is the least significant,
@@ -342,21 +292,6 @@ foreign lib {
*/
unlockpt :: proc(fildes: FD) -> result ---
/*
Uses the string argument to set environment variable values.
Returns: 0 on success, non-zero (setting errno) on failure
Example:
if posix.putenv("HOME=/usr/home") != 0 {
fmt.panicf("putenv failure: %v", posix.strerror(posix.errno()))
}
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/putenv.html ]]
*/
@(link_name=LPUTENV)
putenv :: proc(string: cstring) -> c.int ---
/*
Updates or add a variable in the environment of the calling process.
@@ -427,23 +362,11 @@ foreign lib {
setkey :: proc(key: [^]byte) ---
}
EXIT_FAILURE :: libc.EXIT_FAILURE
EXIT_SUCCESS :: libc.EXIT_SUCCESS
RAND_MAX :: libc.RAND_MAX
MB_CUR_MAX :: libc.MB_CUR_MAX
div_t :: libc.div_t
ldiv_t :: libc.ldiv_t
lldiv_t :: libc.lldiv_t
when ODIN_OS == .NetBSD {
@(private) LPUTENV :: "__putenv50"
@(private) LINITSTATE :: "__initstate60"
@(private) LSRANDOM :: "__srandom60"
@(private) LUNSETENV :: "__unsetenv13"
} else {
@(private) LPUTENV :: "putenv"
@(private) LINITSTATE :: "initstate"
@(private) LSRANDOM :: "srandom"
@(private) LUNSETENV :: "unsetenv"