diff --git a/core/c/libc/stdlib.odin b/core/c/libc/stdlib.odin index 98280e44b..c0e273872 100644 --- a/core/c/libc/stdlib.odin +++ b/core/c/libc/stdlib.odin @@ -42,6 +42,21 @@ when ODIN_OS == .Linux { } } +when ODIN_OS == .Haiku { + RAND_MAX :: 0x7fffffff + + // GLIBC and MUSL only + @(private="file") + @(default_calling_convention="c") + foreign libc { + __ctype_get_mb_cur_max :: proc() -> ushort --- + } + + MB_CUR_MAX :: #force_inline proc() -> size_t { + return size_t(__ctype_get_mb_cur_max()) + } +} + when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .OpenBSD { RAND_MAX :: 0x7fffffff diff --git a/core/os/os_haiku.odin b/core/os/os_haiku.odin index 6b218af07..4a57afb87 100644 --- a/core/os/os_haiku.odin +++ b/core/os/os_haiku.odin @@ -151,6 +151,7 @@ foreign lib { @(link_name="closedir") _unix_closedir :: proc(dirp: Dir) -> c.int --- @(link_name="rewinddir") _unix_rewinddir :: proc(dirp: Dir) --- @(link_name="readdir_r") _unix_readdir_r :: proc(dirp: Dir, entry: ^Dirent, result: ^^Dirent) -> c.int --- + @(link_name="dup") _unix_dup :: proc(fd: Handle) -> Handle --- @(link_name="malloc") _unix_malloc :: proc(size: c.size_t) -> rawptr --- @(link_name="calloc") _unix_calloc :: proc(num, size: c.size_t) -> rawptr --- @@ -158,7 +159,7 @@ foreign lib { @(link_name="realloc") _unix_realloc :: proc(ptr: rawptr, size: c.size_t) -> rawptr --- @(link_name="getenv") _unix_getenv :: proc(cstring) -> cstring --- - @(link_name="realpath") _unix_realpath :: proc(path: cstring, resolved_path: rawptr) -> rawptr --- + @(link_name="realpath") _unix_realpath :: proc(path: cstring, resolved_path: [^]byte = nil) -> cstring --- @(link_name="exit") _unix_exit :: proc(status: c.int) -> ! --- @@ -445,7 +446,7 @@ absolute_path_from_relative :: proc(rel: string, allocator := context.allocator) if path_ptr == nil { return "", get_last_error() } - defer _unix_free(path_ptr) + defer _unix_free(rawptr(path_ptr)) path_cstr := cstring(path_ptr) return strings.clone(string(path_cstr), allocator) @@ -489,3 +490,17 @@ exit :: proc "contextless" (code: int) -> ! { runtime._cleanup_runtime_contextless() _unix_exit(i32(code)) } + +@(require_results) +current_thread_id :: proc "contextless" () -> int { + return int(haiku.find_thread(nil)) +} + +@(private, require_results) +_dup :: proc(fd: Handle) -> (Handle, Error) { + dup := _unix_dup(fd) + if dup == -1 { + return INVALID_HANDLE, get_last_error() + } + return dup, nil +} diff --git a/core/path/filepath/path_unix.odin b/core/path/filepath/path_unix.odin index 35b98a7ae..8bf412599 100644 --- a/core/path/filepath/path_unix.odin +++ b/core/path/filepath/path_unix.odin @@ -1,4 +1,4 @@ -#+build linux, darwin, freebsd, openbsd, netbsd +#+build linux, darwin, freebsd, openbsd, netbsd, haiku package filepath import "base:runtime" diff --git a/core/testing/signal_handler_posix.odin b/core/testing/signal_handler_posix.odin index 1bfcc875b..0efba27dc 100644 --- a/core/testing/signal_handler_posix.odin +++ b/core/testing/signal_handler_posix.odin @@ -1,4 +1,4 @@ -#+build linux, darwin, netbsd, openbsd, freebsd +#+build linux, darwin, netbsd, openbsd, freebsd, haiku #+private package testing