aboutsummaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
authorCiD- <jkercher43@gmail.com>2022-03-23 11:49:19 -0400
committerCiD- <jkercher43@gmail.com>2022-03-23 11:49:19 -0400
commite252d3bedf28e603ee3c33a4aebcfefbb5cfb66c (patch)
tree1a3c0be3772f91ecbfe4570515bd7ac1a03f53e4 /core/os
parent36c22393a4e3026bc84a5ee8d2230d1f6f78b83c (diff)
add os2.name
Diffstat (limited to 'core/os')
-rw-r--r--core/os/os2/file_linux.odin27
1 files changed, 21 insertions, 6 deletions
diff --git a/core/os/os2/file_linux.odin b/core/os/os2/file_linux.odin
index 9030d265d..7040d0ed3 100644
--- a/core/os/os2/file_linux.odin
+++ b/core/os/os2/file_linux.odin
@@ -4,6 +4,7 @@ package os2
import "core:io"
import "core:time"
import "core:strings"
+import "core:strconv"
import "core:sys/unix"
@@ -55,8 +56,20 @@ _close :: proc(fd: Handle) -> Error {
}
_name :: proc(fd: Handle, allocator := context.allocator) -> string {
- //TODO
- return ""
+ // NOTE: Not sure how portable this really is
+ PROC_FD_PATH :: "/proc/self/fd/"
+
+ buf: [32]u8
+ copy(buf[:], PROC_FD_PATH)
+
+ strconv.itoa(buf[len(PROC_FD_PATH):], int(fd))
+
+ realpath: string
+ err: Error
+ if realpath, err = _read_link_cstr(cstring(&buf[0])); err != nil || realpath[0] != '/' {
+ return ""
+ }
+ return realpath
}
_seek :: proc(fd: Handle, offset: i64, whence: Seek_From) -> (ret: i64, err: Error) {
@@ -189,10 +202,7 @@ _symlink :: proc(old_name, new_name: string) -> Error {
return _ok_or_error(unix.sys_symlink(old_name_cstr, new_name_cstr))
}
-_read_link :: proc(name: string, allocator := context.allocator) -> (string, Error) {
- name_cstr := strings.clone_to_cstring(name)
- defer delete(name_cstr)
-
+_read_link_cstr :: proc(name_cstr: cstring, allocator := context.allocator) -> (string, Error) {
bufsz : uint = 256
buf := make([]byte, bufsz, allocator)
for {
@@ -210,6 +220,11 @@ _read_link :: proc(name: string, allocator := context.allocator) -> (string, Err
}
}
+_read_link :: proc(name: string, allocator := context.allocator) -> (string, Error) {
+ name_cstr := strings.clone_to_cstring(name, context.temp_allocator)
+ return _read_link_cstr(name_cstr, allocator)
+}
+
_unlink :: proc(name: string) -> Error {
name_cstr := strings.clone_to_cstring(name, context.temp_allocator)
return _ok_or_error(unix.sys_unlink(name_cstr))