@@ -4,6 +4,8 @@ package libc
when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib"
+} else when ODIN_OS == "darwin" {
+ foreign import libc "system:System.framework"
} else {
foreign import libc "system:c"
}
@@ -2,6 +2,8 @@ package libc
@@ -38,6 +40,20 @@ when ODIN_OS == "windows" {
ERANGE :: 34
+when ODIN_OS == "darwin" {
+ @(private="file")
+ @(default_calling_convention="c")
+ foreign libc {
+ @(link_name="__error")
+ _get_errno :: proc() -> ^int ---
+ }
+
+ // Unknown
+ EDOM :: 33
+ EILSEQ :: 92
+ ERANGE :: 34
+}
// Odin has no way to make an identifier "errno" behave as a function call to
// read the value, or to produce an lvalue such that you can assign a different
// error value to errno. To work around this, just expose it as a function like
@@ -6,6 +6,8 @@ import "core:intrinsics"
@@ -4,10 +4,11 @@ package libc
-
@(default_calling_convention="c")
foreign libc {
@@ -32,7 +34,20 @@ when ODIN_OS == "windows" {
SIGTERM :: 15
-when ODIN_OS == "linux" || ODIN_OS == "freebsd" || ODIN_OS == "darwin" {
+when ODIN_OS == "linux" || ODIN_OS == "freebsd" {
+ SIG_ERR :: rawptr(~uintptr(0))
+ SIG_DFL :: rawptr(uintptr(0))
+ SIG_IGN :: rawptr(uintptr(1))
+ SIGABRT :: 6
+ SIGFPE :: 8
+ SIGILL :: 4
+ SIGINT :: 2
+ SIGSEGV :: 11
+ SIGTERM :: 15
SIG_ERR :: rawptr(~uintptr(0))
SIG_DFL :: rawptr(uintptr(0))
SIG_IGN :: rawptr(uintptr(1))
@@ -67,7 +69,7 @@ when ODIN_OS == "linux" {
SEEK_CUR :: 1
SEEK_END :: 2
- TMP_MAX :: 10000
+ TMP_MAX :: 308915776
stderr: ^FILE
@@ -76,6 +78,36 @@ when ODIN_OS == "linux" {
+ fpos_t :: distinct i64
+ _IOFBF :: 0
+ _IOLBF :: 1
+ _IONBF :: 2
+ BUFSIZ :: 1024
+ EOF :: int(-1)
+ FOPEN_MAX :: 20
+ FILENAME_MAX :: 1024
+ L_tmpnam :: 1024
+ SEEK_SET :: 0
+ SEEK_CUR :: 1
+ SEEK_END :: 2
+ @(link_name="__stderrp") stderr: ^FILE
+ @(link_name="__stdinp") stdin: ^FILE
+ @(link_name="__stdoutp") stdout: ^FILE
// 7.21.4 Operations on files
@@ -33,7 +35,23 @@ when ODIN_OS == "linux" {
MB_CUR_MAX :: #force_inline proc() -> size_t {
- return __ctype_get_mb_cur_max()
+ return size_t(__ctype_get_mb_cur_max())
+ RAND_MAX :: 0x7fffffff
+ // GLIBC and MUSL only
+ ___mb_cur_max :: proc() -> int ---
+ MB_CUR_MAX :: #force_inline proc() -> size_t {
+ return size_t(___mb_cur_max())
@@ -6,6 +6,8 @@ import "core:runtime"
@@ -136,3 +136,8 @@ when ODIN_OS == "linux" {
tss_set :: proc(key: tss_t, val: rawptr) -> int ---
+ // TODO: find out what this is meant to be!
@@ -43,7 +45,7 @@ when ODIN_OS == "windows" {
-when ODIN_OS == "linux" || ODIN_OS == "freebsd" {
+when ODIN_OS == "linux" || ODIN_OS == "freebsd" || ODIN_OS == "darwin" {
// 7.27.2 Time manipulation functions
@@ -75,7 +77,7 @@ when ODIN_OS == "linux" || ODIN_OS == "freebsd" {
tm :: struct {
tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday, tm_yday, tm_isdst: int,
- _: long,
- _: rawptr,
+ tm_gmtoff: long,
+ tm_zone: rawptr,
@@ -14,10 +16,15 @@ when ODIN_OS == "windows" {
when ODIN_OS == "linux" {
- wctrans_t :: distinct rawptr
+ wctrans_t :: distinct intptr_t
wctype_t :: distinct ulong
+ wctrans_t :: distinct int
+ wctype_t :: distinct u32
// 7.30.2.1 Wide character classification functions