aboutsummaryrefslogtreecommitdiff
path: root/core/path/filepath
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-04-11 19:05:01 +0100
committergingerBill <bill@gingerbill.org>2021-04-11 19:05:01 +0100
commite3ee005404ee9ab9308c3fe08b81610d59eec8de (patch)
tree8c14189cffab1b65a4d407c918973f6d6204ded6 /core/path/filepath
parente8bf1f2064da8e4c7811e4f8d94a8c05fd848efe (diff)
Clean up path_unix.odin to make it not depend on `package os`
Diffstat (limited to 'core/path/filepath')
-rw-r--r--core/path/filepath/path_unix.odin44
1 files changed, 38 insertions, 6 deletions
diff --git a/core/path/filepath/path_unix.odin b/core/path/filepath/path_unix.odin
index 8db5064d2..a1e16a3e9 100644
--- a/core/path/filepath/path_unix.odin
+++ b/core/path/filepath/path_unix.odin
@@ -1,8 +1,13 @@
//+build linux, darwin, freebsd
package filepath
+when ODIN_OS == "darwin" {
+ foreign import libc "System.framework"
+} else {
+ foreign import libc "system:c"
+}
+
import "core:strings"
-import "core:os"
SEPARATOR :: '/';
SEPARATOR_STRING :: `/`;
@@ -17,11 +22,20 @@ is_abs :: proc(path: string) -> bool {
}
abs :: proc(path: string, allocator := context.allocator) -> (string, bool) {
- full_path, err := os.absolute_path_from_relative(path);
- if err != os.ERROR_NONE {
- return "", false;
+ rel := path;
+ if rel == "" {
+ rel = ".";
+ }
+ rel_cstr := strings.clone_to_cstring(rel, context.temp_allocator);
+ path_ptr := realpath(rel_cstr, nil);
+ if path_ptr == nil {
+ return "", __error()^ == 0;
}
- return full_path, true;
+ defer _unix_free(path_ptr);
+
+ path_cstr := cstring(path_ptr);
+ path = strings.clone(string(path_cstr), allocator);
+ return path, true;
}
join :: proc(elems: ..string, allocator := context.allocator) -> string {
@@ -32,4 +46,22 @@ join :: proc(elems: ..string, allocator := context.allocator) -> string {
}
}
return "";
-} \ No newline at end of file
+}
+
+@(private)
+foreign libc {
+ realpath :: proc(path: cstring, resolved_path: rawptr) -> rawptr ---
+ @(link_name="free") _unix_free :: proc(ptr: rawptr) ---
+
+}
+when ODIN_OS == "darwin" {
+ @(private)
+ foreign libc {
+ @(link_name="__error") __error :: proc() -> ^i32 ---
+ }
+} else {
+ @(private)
+ foreign libc {
+ @(link_name="__errno_location") __error :: proc() -> ^i32 ---
+ }
+}