summary refs log tree commit diff stats
path: root/lib/pure/os.nim
diff options
context:
space:
mode:
authorEuan <euantorano@users.noreply.github.com>2020-09-18 21:26:53 +0100
committerGitHub <noreply@github.com>2020-09-18 22:26:53 +0200
commitae1f5c15593be8137812137d315bb8d367dfac9f (patch)
tree44cb1efa417f7f59a11e500a11a5e8189cb2a5b1 /lib/pure/os.nim
parent341cd844b282cc6ed3b1fc4c1ef10c38fc06d5e7 (diff)
downloadNim-ae1f5c15593be8137812137d315bb8d367dfac9f.tar.gz
Use sysctl on NetBSD to get exe name (#15359)
Diffstat (limited to 'lib/pure/os.nim')
-rw-r--r--lib/pure/os.nim13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index e7087acf7..45f022379 100644
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -2826,12 +2826,19 @@ when not weirdTarget and (defined(freebsd) or defined(dragonfly)):
 
   when defined(freebsd):
     const KERN_PROC_PATHNAME = 12
+  elif defined(netbsd):
+    const KERN_PROC_ARGS = 48
+    const KERN_PROC_PATHNAME = 5
   else:
     const KERN_PROC_PATHNAME = 9
 
   proc getApplFreebsd(): string =
     var pathLength = csize_t(0)
-    var req = [CTL_KERN.cint, KERN_PROC.cint, KERN_PROC_PATHNAME.cint, -1.cint]
+
+    when defined(netbsd):
+      var req = [CTL_KERN.cint, KERN_PROC_ARGS.cint, -1.cint, KERN_PROC_PATHNAME.cint]
+    else:
+      var req = [CTL_KERN.cint, KERN_PROC.cint, KERN_PROC_PATHNAME.cint, -1.cint]
 
     # first call to get the required length
     var res = sysctl(addr req[0], 4, nil, addr pathLength, nil, 0)
@@ -2984,13 +2991,13 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noW
     if result.len > 0:
       result = result.expandFilename
   else:
-    when defined(linux) or defined(aix) or defined(netbsd):
+    when defined(linux) or defined(aix):
       result = getApplAux("/proc/self/exe")
     elif defined(solaris):
       result = getApplAux("/proc/" & $getpid() & "/path/a.out")
     elif defined(genode) or defined(nintendoswitch):
       raiseOSError(OSErrorCode(-1), "POSIX command line not supported")
-    elif defined(freebsd) or defined(dragonfly):
+    elif defined(freebsd) or defined(dragonfly) or defined(netbsd):
       result = getApplFreebsd()
     elif defined(haiku):
       result = getApplHaiku()