mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
vendor/libc: a bunch of additions
All these additions are to allow Dear ImGui to be compiled natively.
This commit is contained in:
Vendored
+72
-1
@@ -1,8 +1,10 @@
|
||||
package odin_libc
|
||||
|
||||
import "base:intrinsics"
|
||||
import "base:runtime"
|
||||
|
||||
import "core:c"
|
||||
import "core:os"
|
||||
import "core:slice"
|
||||
import "core:sort"
|
||||
import "core:strconv"
|
||||
@@ -108,12 +110,81 @@ atof :: proc "c" (str: cstring) -> f64 {
|
||||
@(require, linkage="strong", link_name="strtol")
|
||||
strtol :: proc "c" (str: cstring, str_end: ^cstring, base: i32) -> c.long {
|
||||
context = g_ctx
|
||||
|
||||
sstr := string(str)
|
||||
sstr = strings.trim_left_space(sstr)
|
||||
|
||||
n: int
|
||||
i, _ := strconv.parse_i64_of_base(sstr, int(base), &n)
|
||||
str_end ^= cstring(raw_data(sstr)[n:])
|
||||
if str_end != nil {
|
||||
str_end ^= cstring(raw_data(sstr)[n:])
|
||||
}
|
||||
return c.long(clamp(i, i64(min(c.long)), i64(max(c.long))))
|
||||
}
|
||||
|
||||
@(require, linkage="strong", link_name="strtod")
|
||||
strtod :: proc "c" (str: cstring, str_end: ^cstring) -> c.double {
|
||||
context = g_ctx
|
||||
|
||||
sstr := string(str)
|
||||
sstr = strings.trim_left_space(sstr)
|
||||
|
||||
n: int
|
||||
val, _ := strconv.parse_f64(sstr, &n)
|
||||
if str_end != nil {
|
||||
str_end ^= cstring(raw_data(sstr)[n:])
|
||||
}
|
||||
|
||||
return c.double(val)
|
||||
}
|
||||
|
||||
@(require, linkage="strong", link_name="abort")
|
||||
abort :: proc "c" () -> ! {
|
||||
intrinsics.trap()
|
||||
}
|
||||
|
||||
ATEXIT_MAX :: 32
|
||||
|
||||
@(private)
|
||||
atexit_functions: [ATEXIT_MAX]proc "c" ()
|
||||
@(private)
|
||||
atexit_functions_count: int
|
||||
|
||||
@(require, linkage="strong", link_name="atexit")
|
||||
atexit :: proc "c" (function: proc "c" ()) -> i32 {
|
||||
entry := intrinsics.atomic_add(&atexit_functions_count, 1)
|
||||
if entry >= ATEXIT_MAX {
|
||||
return -1
|
||||
}
|
||||
|
||||
atexit_functions[entry] = function
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@(require, linkage="strong", link_name="exit")
|
||||
exit :: proc "c" (exit_code: c.int) -> ! {
|
||||
finish_atexit()
|
||||
os.exit(int(exit_code))
|
||||
}
|
||||
|
||||
@(private, fini)
|
||||
finish_atexit :: proc "c" () {
|
||||
n := intrinsics.atomic_exchange(&atexit_functions_count, 0)
|
||||
for function in atexit_functions[:n] {
|
||||
function()
|
||||
}
|
||||
}
|
||||
|
||||
ldiv_t :: struct {
|
||||
quot: c.long,
|
||||
rem: c.long,
|
||||
}
|
||||
|
||||
@(require, linkage="strong", link_name="ldiv")
|
||||
ldiv :: proc "c" (number: c.long, denom: c.long) -> ldiv_t {
|
||||
return {
|
||||
quot = number / denom,
|
||||
rem = number %% denom,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user