aboutsummaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-04-12 15:22:40 +0100
committergingerBill <bill@gingerbill.org>2021-04-12 15:22:40 +0100
commit4fb4ada2c72233de59dbf708bcd3a6ffcfec3953 (patch)
tree9e81dd6d9f53e1ed43ee0f3c86cf43c632ca6a48 /core/os
parente3ee005404ee9ab9308c3fe08b81610d59eec8de (diff)
Update sync2 to just use atomic intrinsics rather than the parapoly wrappers
Diffstat (limited to 'core/os')
-rw-r--r--core/os/stat_unix.odin37
1 files changed, 33 insertions, 4 deletions
diff --git a/core/os/stat_unix.odin b/core/os/stat_unix.odin
index fa013cefb..b1f427828 100644
--- a/core/os/stat_unix.odin
+++ b/core/os/stat_unix.odin
@@ -2,7 +2,6 @@
package os
import "core:time"
-import "core:path"
/*
For reference
@@ -71,6 +70,36 @@ _fill_file_info_from_stat :: proc(fi: ^File_Info, s: OS_Stat) {
fi.access_time = _make_time_from_unix_file_time(s.last_access);
}
+
+@private
+path_base :: proc(path: string) -> string {
+ is_separator :: proc(c: byte) -> bool {
+ return c == '/';
+ }
+
+ if path == "" {
+ return ".";
+ }
+
+ path := path;
+ for len(path) > 0 && is_separator(path[len(path)-1]) {
+ path = path[:len(path)-1];
+ }
+
+ i := len(path)-1;
+ for i >= 0 && !is_separator(path[i]) {
+ i -= 1;
+ }
+ if i >= 0 {
+ path = path[i+1:];
+ }
+ if path == "" {
+ return "/";
+ }
+ return path;
+}
+
+
lstat :: proc(name: string, allocator := context.allocator) -> (fi: File_Info, err: Errno) {
context.allocator = allocator;
@@ -85,7 +114,7 @@ lstat :: proc(name: string, allocator := context.allocator) -> (fi: File_Info, e
if err != ERROR_NONE {
return;
}
- fi.name = path.base(fi.fullpath);
+ fi.name = path_base(fi.fullpath);
return fi, ERROR_NONE;
}
@@ -103,7 +132,7 @@ stat :: proc(name: string, allocator := context.allocator) -> (fi: File_Info, er
if err != ERROR_NONE {
return;
}
- fi.name = path.base(fi.fullpath);
+ fi.name = path_base(fi.fullpath);
return fi, ERROR_NONE;
}
@@ -121,6 +150,6 @@ fstat :: proc(fd: Handle, allocator := context.allocator) -> (fi: File_Info, err
if err != ERROR_NONE {
return;
}
- fi.name = path.base(fi.fullpath);
+ fi.name = path_base(fi.fullpath);
return fi, ERROR_NONE;
}