mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
os2: fix lstat logic
This commit is contained in:
@@ -96,8 +96,7 @@ _remove_all :: proc(path: string) -> Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_get_working_directory :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
_get_working_directory :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
||||||
assert(!is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
||||||
TEMP_ALLOCATOR_GUARD()
|
|
||||||
|
|
||||||
buf: [dynamic]byte
|
buf: [dynamic]byte
|
||||||
buf.allocator = temp_allocator()
|
buf.allocator = temp_allocator()
|
||||||
|
|||||||
+24
-10
@@ -97,24 +97,38 @@ _lstat :: proc(name: string, allocator: runtime.Allocator) -> (fi: File_Info, er
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(!is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
||||||
TEMP_ALLOCATOR_GUARD()
|
|
||||||
cname := temp_cstring(name) or_return
|
|
||||||
|
|
||||||
rcname := posix.realpath(cname)
|
// NOTE: can't use realpath here because it tries to resolve symlinks.
|
||||||
if rcname == nil {
|
|
||||||
err = .Invalid_Path
|
// NOTE: This might not be correct when given "/symlink/foo.txt",
|
||||||
return
|
// you would want that to resolve "/symlink", but not resolve "foo.txt".
|
||||||
|
|
||||||
|
fullpath := filepath.clean(name, temp_allocator())
|
||||||
|
assert(len(fullpath) > 0)
|
||||||
|
switch {
|
||||||
|
case fullpath[0] == '/':
|
||||||
|
// nothing.
|
||||||
|
case fullpath == ".":
|
||||||
|
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,
|
||||||
|
"/",
|
||||||
|
fullpath,
|
||||||
|
}, temp_allocator()) or_return
|
||||||
}
|
}
|
||||||
defer posix.free(rcname)
|
|
||||||
|
|
||||||
stat: posix.stat_t
|
stat: posix.stat_t
|
||||||
if posix.lstat(rcname, &stat) != .OK {
|
if posix.lstat(temp_cstring(fullpath), &stat) != .OK {
|
||||||
err = _get_platform_error()
|
err = _get_platform_error()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fullpath := clone_string(string(rcname), allocator) or_return
|
fullpath = clone_string(fullpath, allocator) or_return
|
||||||
return internal_stat(stat, fullpath), nil
|
return internal_stat(stat, fullpath), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user