Haiku: small fixes across core

This commit is contained in:
avanspector
2025-01-10 07:07:40 +01:00
parent 9868c8292b
commit 0a985f5d02
4 changed files with 34 additions and 4 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -1,4 +1,4 @@
#+build linux, darwin, freebsd, openbsd, netbsd
#+build linux, darwin, freebsd, openbsd, netbsd, haiku
package filepath
import "base:runtime"

View File

@@ -1,4 +1,4 @@
#+build linux, darwin, netbsd, openbsd, freebsd
#+build linux, darwin, netbsd, openbsd, freebsd, haiku
#+private
package testing