Browse Source

Updated core lib and did cleanup

Updated core with some path related functions and did some minor code cleanup.
Most of the standard library function is just a matter of copy what is there for the other BSDs.
Andreas T Jonsson 1 year ago
parent
commit
38640d5d9e

+ 1 - 0
core/os/dir_freebsd.odin → core/os/dir_bsd.odin

@@ -1,3 +1,4 @@
+//+build freebsd, netbsd
 package os
 
 import "core:mem"

+ 7 - 0
core/os/os_netbsd.odin

@@ -483,6 +483,13 @@ is_dir_path :: proc(path: string, follow_links: bool = true) -> bool {
 is_file :: proc {is_file_path, is_file_handle}
 is_dir :: proc {is_dir_path, is_dir_handle}
 
+exists :: proc(path: string) -> bool {
+	runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
+	cpath := strings.clone_to_cstring(path, context.temp_allocator)
+	res := _unix_access(cpath, O_RDONLY)
+	return res == 0
+}
+
 // NOTE(bill): Uses startup to initialize it
 
 stdin: Handle  = 0

+ 2 - 2
core/path/filepath/path_unix.odin

@@ -1,4 +1,4 @@
-//+build linux, darwin, freebsd, openbsd
+//+build linux, darwin, freebsd, openbsd, netbsd
 package filepath
 
 when ODIN_OS == .Darwin {
@@ -61,7 +61,7 @@ when ODIN_OS == .Darwin {
 	foreign libc {
 		@(link_name="__error")          __error :: proc() -> ^i32 ---
 	}
-} else when ODIN_OS == .OpenBSD {
+} else when ODIN_OS == .OpenBSD || ODIN_OS == .NetBSD {
 	@(private)
 	foreign libc {
 		@(link_name="__errno")		__error :: proc() -> ^i32 ---

+ 2 - 2
core/sys/unix/signal_netbsd.odin

@@ -13,8 +13,8 @@ SIG_BLOCK   :: 1
 SIG_UNBLOCK :: 2
 SIG_SETMASK :: 3
 
-siginfo_t :: struct { si_pad: [128]c.char }
-sigset_t :: struct { bits: [4]u32 }
+siginfo_t :: struct { _: [128]u8 }
+sigset_t :: struct { _: [4]u32 }
 
 foreign libc {
 	@(link_name="__sigemptyset14")  sigemptyset  :: proc(set: ^sigset_t) -> c.int ---

+ 2 - 2
core/thread/thread_unix.odin

@@ -20,7 +20,7 @@ Thread_Os_Specific :: struct #align(16) {
 // It then waits for `start` to be called.
 //
 _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread {
-	__linux_thread_entry_proc :: proc "c" (t: rawptr) -> rawptr {
+	__unix_thread_entry_proc :: proc "c" (t: rawptr) -> rawptr {
 		t := (^Thread)(t)
 
 		when ODIN_OS != .Darwin {
@@ -109,7 +109,7 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread {
 	assert(res == 0)
 
 	thread.procedure = procedure
-	if unix.pthread_create(&thread.unix_thread, &attrs, __linux_thread_entry_proc, thread) != 0 {
+	if unix.pthread_create(&thread.unix_thread, &attrs, __unix_thread_entry_proc, thread) != 0 {
 		free(thread, thread.creation_allocator)
 		return nil
 	}