diff --git a/core/c/libc/complex.odin b/core/c/libc/complex.odin index e91d39023..62b28f0cd 100644 --- a/core/c/libc/complex.odin +++ b/core/c/libc/complex.odin @@ -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" } diff --git a/core/c/libc/ctype.odin b/core/c/libc/ctype.odin index 9e4b31208..05d9dcd37 100644 --- a/core/c/libc/ctype.odin +++ b/core/c/libc/ctype.odin @@ -2,6 +2,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" } diff --git a/core/c/libc/errno.odin b/core/c/libc/errno.odin index dd17ce515..8ebe2f734 100644 --- a/core/c/libc/errno.odin +++ b/core/c/libc/errno.odin @@ -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" } @@ -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 diff --git a/core/c/libc/math.odin b/core/c/libc/math.odin index c1c51fa25..ee702b82e 100644 --- a/core/c/libc/math.odin +++ b/core/c/libc/math.odin @@ -6,6 +6,8 @@ import "core:intrinsics" 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" } diff --git a/core/c/libc/setjmp.odin b/core/c/libc/setjmp.odin index 4f3ae3aa3..dcd4a9c64 100644 --- a/core/c/libc/setjmp.odin +++ b/core/c/libc/setjmp.odin @@ -4,10 +4,11 @@ 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" } - when ODIN_OS == "windows" { @(default_calling_convention="c") foreign libc { diff --git a/core/c/libc/signal.odin b/core/c/libc/signal.odin index ad007287e..e1044dc02 100644 --- a/core/c/libc/signal.odin +++ b/core/c/libc/signal.odin @@ -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" } @@ -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 +} + +when ODIN_OS == "darwin" { SIG_ERR :: rawptr(~uintptr(0)) SIG_DFL :: rawptr(uintptr(0)) SIG_IGN :: rawptr(uintptr(1)) diff --git a/core/c/libc/stdio.odin b/core/c/libc/stdio.odin index 89891f82e..4a39c22e9 100644 --- a/core/c/libc/stdio.odin +++ b/core/c/libc/stdio.odin @@ -2,6 +2,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" } @@ -67,7 +69,7 @@ when ODIN_OS == "linux" { SEEK_CUR :: 1 SEEK_END :: 2 - TMP_MAX :: 10000 + TMP_MAX :: 308915776 foreign libc { stderr: ^FILE @@ -76,6 +78,36 @@ when ODIN_OS == "linux" { } } +when ODIN_OS == "darwin" { + 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 + + TMP_MAX :: 308915776 + + foreign libc { + @(link_name="__stderrp") stderr: ^FILE + @(link_name="__stdinp") stdin: ^FILE + @(link_name="__stdoutp") stdout: ^FILE + } +} + @(default_calling_convention="c") foreign libc { // 7.21.4 Operations on files diff --git a/core/c/libc/stdlib.odin b/core/c/libc/stdlib.odin index 0e24b0d5c..b368c0cee 100644 --- a/core/c/libc/stdlib.odin +++ b/core/c/libc/stdlib.odin @@ -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" } @@ -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()) + } +} + + +when ODIN_OS == "darwin" { + RAND_MAX :: 0x7fffffff + + // GLIBC and MUSL only + @(private="file") + @(default_calling_convention="c") + foreign libc { + ___mb_cur_max :: proc() -> int --- + } + + MB_CUR_MAX :: #force_inline proc() -> size_t { + return size_t(___mb_cur_max()) } } diff --git a/core/c/libc/string.odin b/core/c/libc/string.odin index cd577237c..c91124dcb 100644 --- a/core/c/libc/string.odin +++ b/core/c/libc/string.odin @@ -6,6 +6,8 @@ import "core:runtime" 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" } diff --git a/core/c/libc/threads.odin b/core/c/libc/threads.odin index 630216d06..ad305b517 100644 --- a/core/c/libc/threads.odin +++ b/core/c/libc/threads.odin @@ -136,3 +136,8 @@ when ODIN_OS == "linux" { tss_set :: proc(key: tss_t, val: rawptr) -> int --- } } + + +when ODIN_OS == "darwin" { + // TODO: find out what this is meant to be! +} diff --git a/core/c/libc/time.odin b/core/c/libc/time.odin index 7cc677bff..96e80e216 100644 --- a/core/c/libc/time.odin +++ b/core/c/libc/time.odin @@ -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" } @@ -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" { @(default_calling_convention="c") foreign libc { // 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, } } diff --git a/core/c/libc/uchar.odin b/core/c/libc/uchar.odin index 978d9b7bf..e49c29e51 100644 --- a/core/c/libc/uchar.odin +++ b/core/c/libc/uchar.odin @@ -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" } diff --git a/core/c/libc/wchar.odin b/core/c/libc/wchar.odin index d88a49dd9..fc206e494 100644 --- a/core/c/libc/wchar.odin +++ b/core/c/libc/wchar.odin @@ -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" } diff --git a/core/c/libc/wctype.odin b/core/c/libc/wctype.odin index 24af30c97..47f17e0b4 100644 --- a/core/c/libc/wctype.odin +++ b/core/c/libc/wctype.odin @@ -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" } @@ -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 } +when ODIN_OS == "darwin" { + wctrans_t :: distinct int + wctype_t :: distinct u32 +} + @(default_calling_convention="c") foreign libc { // 7.30.2.1 Wide character classification functions