瀏覽代碼

Haiku: small fixes across core

avanspector 8 月之前
父節點
當前提交
0a985f5d02
共有 4 個文件被更改,包括 34 次插入4 次删除
  1. 15 0
      core/c/libc/stdlib.odin
  2. 17 2
      core/os/os_haiku.odin
  3. 1 1
      core/path/filepath/path_unix.odin
  4. 1 1
      core/testing/signal_handler_posix.odin

+ 15 - 0
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

+ 17 - 2
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
+}

+ 1 - 1
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"

+ 1 - 1
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