mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
os2: remove libc use on Linux
This commit is contained in:
@@ -207,3 +207,21 @@ _get_full_path :: proc(fd: linux.Fd, allocator: runtime.Allocator) -> (fullpath:
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_get_absolute_path :: proc(path: string, allocator: runtime.Allocator) -> (absolute_path: string, err: Error) {
|
||||||
|
rel := path
|
||||||
|
if rel == "" {
|
||||||
|
rel = "."
|
||||||
|
}
|
||||||
|
|
||||||
|
temp_allocator := TEMP_ALLOCATOR_GUARD({ allocator })
|
||||||
|
|
||||||
|
fd, errno := linux.open(clone_to_cstring(path, temp_allocator) or_return, {})
|
||||||
|
if errno != nil {
|
||||||
|
err = _get_platform_error(errno)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer linux.close(fd)
|
||||||
|
|
||||||
|
return _get_full_path(fd, allocator)
|
||||||
|
}
|
||||||
|
|||||||
@@ -123,3 +123,20 @@ _set_working_directory :: proc(dir: string) -> (err: Error) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_get_absolute_path :: proc(path: string, allocator: runtime.Allocator) -> (absolute_path: string, err: Error) {
|
||||||
|
rel := path
|
||||||
|
if rel == "" {
|
||||||
|
rel = "."
|
||||||
|
}
|
||||||
|
temp_allocator := TEMP_ALLOCATOR_GUARD({ allocator })
|
||||||
|
rel_cstr := clone_to_cstring(rel, temp_allocator) or_return
|
||||||
|
path_ptr := posix.realpath(rel_cstr, nil)
|
||||||
|
if path_ptr == nil {
|
||||||
|
return "", Platform_Error(posix.errno())
|
||||||
|
}
|
||||||
|
defer posix.free(path_ptr)
|
||||||
|
|
||||||
|
path_str := clone_string(string(path_ptr), allocator) or_return
|
||||||
|
return path_str, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,10 +4,6 @@ package os2
|
|||||||
|
|
||||||
// This implementation is for all systems that have POSIX-compliant filesystem paths.
|
// This implementation is for all systems that have POSIX-compliant filesystem paths.
|
||||||
|
|
||||||
import "base:runtime"
|
|
||||||
import "core:strings"
|
|
||||||
import "core:sys/posix"
|
|
||||||
|
|
||||||
_are_paths_identical :: proc(a, b: string) -> (identical: bool) {
|
_are_paths_identical :: proc(a, b: string) -> (identical: bool) {
|
||||||
return a == b
|
return a == b
|
||||||
}
|
}
|
||||||
@@ -26,23 +22,6 @@ _is_absolute_path :: proc(path: string) -> bool {
|
|||||||
return len(path) > 0 && _is_path_separator(path[0])
|
return len(path) > 0 && _is_path_separator(path[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
_get_absolute_path :: proc(path: string, allocator: runtime.Allocator) -> (absolute_path: string, err: Error) {
|
|
||||||
rel := path
|
|
||||||
if rel == "" {
|
|
||||||
rel = "."
|
|
||||||
}
|
|
||||||
temp_allocator := TEMP_ALLOCATOR_GUARD({ allocator })
|
|
||||||
rel_cstr := strings.clone_to_cstring(rel, temp_allocator)
|
|
||||||
path_ptr := posix.realpath(rel_cstr, nil)
|
|
||||||
if path_ptr == nil {
|
|
||||||
return "", Platform_Error(posix.errno())
|
|
||||||
}
|
|
||||||
defer posix.free(path_ptr)
|
|
||||||
|
|
||||||
path_str := strings.clone(string(path_ptr), allocator)
|
|
||||||
return path_str, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
_get_relative_path_handle_start :: proc(base, target: string) -> bool {
|
_get_relative_path_handle_start :: proc(base, target: string) -> bool {
|
||||||
base_rooted := len(base) > 0 && _is_path_separator(base[0])
|
base_rooted := len(base) > 0 && _is_path_separator(base[0])
|
||||||
target_rooted := len(target) > 0 && _is_path_separator(target[0])
|
target_rooted := len(target) > 0 && _is_path_separator(target[0])
|
||||||
|
|||||||
Reference in New Issue
Block a user