os/os2: add get_executable_path and get_executable_directory

This commit is contained in:
Laytan Laats
2025-01-21 18:54:45 +01:00
parent 223970671f
commit b673642412
10 changed files with 234 additions and 3 deletions
+20
View File
@@ -136,6 +136,26 @@ _set_working_directory :: proc(dir: string) -> (err: Error) {
return
}
_get_executable_path :: proc(allocator: runtime.Allocator) -> (path: string, err: Error) {
TEMP_ALLOCATOR_GUARD()
buf := make([dynamic]u16, 512, temp_allocator()) or_return
for {
ret := win32.GetModuleFileNameW(nil, raw_data(buf), win32.DWORD(len(buf)))
if ret == 0 {
err = _get_platform_error()
return
}
if ret == win32.DWORD(len(buf)) && win32.GetLastError() == win32.ERROR_INSUFFICIENT_BUFFER {
resize(&buf, len(buf)*2) or_return
continue
}
return win32_utf16_to_utf8(buf[:ret], allocator)
}
}
can_use_long_paths: bool
@(init)