path_netbsd.odin 520 B

123456789101112131415161718192021222324
  1. package os2
  2. import "base:runtime"
  3. import "core:sys/posix"
  4. _get_executable_path :: proc(allocator: runtime.Allocator) -> (path: string, err: Error) {
  5. temp_allocator := TEMP_ALLOCATOR_GUARD({ allocator })
  6. buf := make([dynamic]byte, 1024, temp_allocator) or_return
  7. for {
  8. n := posix.readlink("/proc/curproc/exe", raw_data(buf), len(buf))
  9. if n < 0 {
  10. err = _get_platform_error()
  11. return
  12. }
  13. if n < len(buf) {
  14. return clone_string(string(buf[:n]), allocator)
  15. }
  16. resize(&buf, len(buf)*2) or_return
  17. }
  18. }