os2: Resolve temp allocator collisions

This commit is contained in:
Lucas Perlind
2025-05-08 17:41:01 +10:00
parent 4a709086a4
commit b9db1dd3e0
34 changed files with 319 additions and 314 deletions
+8 -8
View File
@@ -69,8 +69,8 @@ _stat :: proc(name: string, allocator: runtime.Allocator) -> (fi: File_Info, err
return
}
TEMP_ALLOCATOR_GUARD()
cname := temp_cstring(name) or_return
temp_allocator := get_temp_allocator(TEMP_ALLOCATOR_GUARD({ allocator }))
cname := clone_to_cstring(name, temp_allocator) or_return
fd := posix.open(cname, {})
if fd == -1 {
@@ -96,33 +96,33 @@ _lstat :: proc(name: string, allocator: runtime.Allocator) -> (fi: File_Info, er
return
}
TEMP_ALLOCATOR_GUARD()
temp_allocator := get_temp_allocator(TEMP_ALLOCATOR_GUARD({ allocator }))
// NOTE: can't use realpath or open (+ fcntl F_GETPATH) here because it tries to resolve symlinks.
// NOTE: This might not be correct when given "/symlink/foo.txt",
// you would want that to resolve "/symlink", but not resolve "foo.txt".
fullpath := clean_path(name, temp_allocator()) or_return
fullpath := clean_path(name, temp_allocator) or_return
assert(len(fullpath) > 0)
switch {
case fullpath[0] == '/':
// nothing.
case fullpath == ".":
fullpath = getwd(temp_allocator()) or_return
fullpath = getwd(temp_allocator) or_return
case len(fullpath) > 1 && fullpath[0] == '.' && fullpath[1] == '/':
fullpath = fullpath[2:]
fallthrough
case:
fullpath = concatenate({
getwd(temp_allocator()) or_return,
getwd(temp_allocator) or_return,
"/",
fullpath,
}, temp_allocator()) or_return
}, temp_allocator) or_return
}
stat: posix.stat_t
if posix.lstat(temp_cstring(fullpath), &stat) != .OK {
if posix.lstat(clone_to_cstring(fullpath), &stat, temp_allocator) != .OK {
err = _get_platform_error()
return
}