Add support for darwin to core:c/libc

This commit is contained in:
gingerBill
2021-11-16 21:19:08 +00:00
parent bb7703fcec
commit f09638318f
14 changed files with 116 additions and 8 deletions
+2
View File
@@ -4,6 +4,8 @@ package libc
when ODIN_OS == "windows" { when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib" foreign import libc "system:libucrt.lib"
} else when ODIN_OS == "darwin" {
foreign import libc "system:System.framework"
} else { } else {
foreign import libc "system:c" foreign import libc "system:c"
} }
+2
View File
@@ -2,6 +2,8 @@ package libc
when ODIN_OS == "windows" { when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib" foreign import libc "system:libucrt.lib"
} else when ODIN_OS == "darwin" {
foreign import libc "system:System.framework"
} else { } else {
foreign import libc "system:c" foreign import libc "system:c"
} }
+16
View File
@@ -4,6 +4,8 @@ package libc
when ODIN_OS == "windows" { when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib" foreign import libc "system:libucrt.lib"
} else when ODIN_OS == "darwin" {
foreign import libc "system:System.framework"
} else { } else {
foreign import libc "system:c" foreign import libc "system:c"
} }
@@ -38,6 +40,20 @@ when ODIN_OS == "windows" {
ERANGE :: 34 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 // 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 // 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 // error value to errno. To work around this, just expose it as a function like
+2
View File
@@ -6,6 +6,8 @@ import "core:intrinsics"
when ODIN_OS == "windows" { when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib" foreign import libc "system:libucrt.lib"
} else when ODIN_OS == "darwin" {
foreign import libc "system:System.framework"
} else { } else {
foreign import libc "system:c" foreign import libc "system:c"
} }
+2 -1
View File
@@ -4,10 +4,11 @@ package libc
when ODIN_OS == "windows" { when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib" foreign import libc "system:libucrt.lib"
} else when ODIN_OS == "darwin" {
foreign import libc "system:System.framework"
} else { } else {
foreign import libc "system:c" foreign import libc "system:c"
} }
when ODIN_OS == "windows" { when ODIN_OS == "windows" {
@(default_calling_convention="c") @(default_calling_convention="c")
foreign libc { foreign libc {
+16 -1
View File
@@ -4,6 +4,8 @@ package libc
when ODIN_OS == "windows" { when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib" foreign import libc "system:libucrt.lib"
} else when ODIN_OS == "darwin" {
foreign import libc "system:System.framework"
} else { } else {
foreign import libc "system:c" foreign import libc "system:c"
} }
@@ -32,7 +34,20 @@ when ODIN_OS == "windows" {
SIGTERM :: 15 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_ERR :: rawptr(~uintptr(0))
SIG_DFL :: rawptr(uintptr(0)) SIG_DFL :: rawptr(uintptr(0))
SIG_IGN :: rawptr(uintptr(1)) SIG_IGN :: rawptr(uintptr(1))
+33 -1
View File
@@ -2,6 +2,8 @@ package libc
when ODIN_OS == "windows" { when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib" foreign import libc "system:libucrt.lib"
} else when ODIN_OS == "darwin" {
foreign import libc "system:System.framework"
} else { } else {
foreign import libc "system:c" foreign import libc "system:c"
} }
@@ -67,7 +69,7 @@ when ODIN_OS == "linux" {
SEEK_CUR :: 1 SEEK_CUR :: 1
SEEK_END :: 2 SEEK_END :: 2
TMP_MAX :: 10000 TMP_MAX :: 308915776
foreign libc { foreign libc {
stderr: ^FILE 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") @(default_calling_convention="c")
foreign libc { foreign libc {
// 7.21.4 Operations on files // 7.21.4 Operations on files
+19 -1
View File
@@ -4,6 +4,8 @@ package libc
when ODIN_OS == "windows" { when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib" foreign import libc "system:libucrt.lib"
} else when ODIN_OS == "darwin" {
foreign import libc "system:System.framework"
} else { } else {
foreign import libc "system:c" foreign import libc "system:c"
} }
@@ -33,7 +35,23 @@ when ODIN_OS == "linux" {
} }
MB_CUR_MAX :: #force_inline proc() -> size_t { 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())
} }
} }
+2
View File
@@ -6,6 +6,8 @@ import "core:runtime"
when ODIN_OS == "windows" { when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib" foreign import libc "system:libucrt.lib"
} else when ODIN_OS == "darwin" {
foreign import libc "system:System.framework"
} else { } else {
foreign import libc "system:c" foreign import libc "system:c"
} }
+5
View File
@@ -136,3 +136,8 @@ when ODIN_OS == "linux" {
tss_set :: proc(key: tss_t, val: rawptr) -> int --- tss_set :: proc(key: tss_t, val: rawptr) -> int ---
} }
} }
when ODIN_OS == "darwin" {
// TODO: find out what this is meant to be!
}
+5 -3
View File
@@ -4,6 +4,8 @@ package libc
when ODIN_OS == "windows" { when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib" foreign import libc "system:libucrt.lib"
} else when ODIN_OS == "darwin" {
foreign import libc "system:System.framework"
} else { } else {
foreign import libc "system:c" 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") @(default_calling_convention="c")
foreign libc { foreign libc {
// 7.27.2 Time manipulation functions // 7.27.2 Time manipulation functions
@@ -75,7 +77,7 @@ when ODIN_OS == "linux" || ODIN_OS == "freebsd" {
tm :: struct { tm :: struct {
tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday, tm_yday, tm_isdst: int, tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday, tm_yday, tm_isdst: int,
_: long, tm_gmtoff: long,
_: rawptr, tm_zone: rawptr,
} }
} }
+2
View File
@@ -4,6 +4,8 @@ package libc
when ODIN_OS == "windows" { when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib" foreign import libc "system:libucrt.lib"
} else when ODIN_OS == "darwin" {
foreign import libc "system:System.framework"
} else { } else {
foreign import libc "system:c" foreign import libc "system:c"
} }
+2
View File
@@ -4,6 +4,8 @@ package libc
when ODIN_OS == "windows" { when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib" foreign import libc "system:libucrt.lib"
} else when ODIN_OS == "darwin" {
foreign import libc "system:System.framework"
} else { } else {
foreign import libc "system:c" foreign import libc "system:c"
} }
+8 -1
View File
@@ -4,6 +4,8 @@ package libc
when ODIN_OS == "windows" { when ODIN_OS == "windows" {
foreign import libc "system:libucrt.lib" foreign import libc "system:libucrt.lib"
} else when ODIN_OS == "darwin" {
foreign import libc "system:System.framework"
} else { } else {
foreign import libc "system:c" foreign import libc "system:c"
} }
@@ -14,10 +16,15 @@ when ODIN_OS == "windows" {
} }
when ODIN_OS == "linux" { when ODIN_OS == "linux" {
wctrans_t :: distinct rawptr wctrans_t :: distinct intptr_t
wctype_t :: distinct ulong wctype_t :: distinct ulong
} }
when ODIN_OS == "darwin" {
wctrans_t :: distinct int
wctype_t :: distinct u32
}
@(default_calling_convention="c") @(default_calling_convention="c")
foreign libc { foreign libc {
// 7.30.2.1 Wide character classification functions // 7.30.2.1 Wide character classification functions