summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-09-24 20:16:57 +0200
committerGitHub <noreply@github.com>2018-09-24 20:16:57 +0200
commit276a05e57d754ef8e3062eeb26898aa3c4f7f333 (patch)
tree1c6fdff87222e56aa792b92ee0f43b8c9800f075
parent9a9005622b9aec69f48fe80344fc4d500862c578 (diff)
parent8cc1c556200fd6948f9bab167f51dae0ec4ae92d (diff)
downloadNim-276a05e57d754ef8e3062eeb26898aa3c4f7f333.tar.gz
Merge pull request #9060 from alaviss/haiku-getAppFilename
os: add getAppFilename() implementation for Haiku
-rw-r--r--lib/pure/os.nim20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index 91d4f0f9d..5c7d369c9 100644
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -1476,6 +1476,24 @@ when defined(macosx):
   proc getExecPath2(c: cstring, size: var cuint32): bool {.
     importc: "_NSGetExecutablePath", header: "<mach-o/dyld.h>".}
 
+when defined(haiku):
+  const
+    PATH_MAX = 1024
+    B_FIND_PATH_IMAGE_PATH = 1000
+
+  proc find_path(codePointer: pointer, baseDirectory: cint, subPath: cstring,
+                 pathBuffer: cstring, bufferSize: csize): int32
+                {.importc, header: "<FindDirectory.h>".}
+
+  proc getApplHaiku(): string =
+    result = newString(PATH_MAX)
+
+    if find_path(nil, B_FIND_PATH_IMAGE_PATH, nil, result, PATH_MAX) == 0:
+      let realLen = len(cstring(result))
+      setLen(result, realLen)
+    else:
+      result = ""
+
 proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} =
   ## Returns the filename of the application's executable.
   ##
@@ -1530,6 +1548,8 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} =
       raiseOSError(OSErrorCode(-1), "POSIX command line not supported")
     elif defined(freebsd) or defined(dragonfly):
       result = getApplFreebsd()
+    elif defined(haiku):
+      result = getApplHaiku()
     # little heuristic that may work on other POSIX-like systems:
     if result.len == 0:
       result = getApplHeuristic()