From 8cc1c556200fd6948f9bab167f51dae0ec4ae92d Mon Sep 17 00:00:00 2001 From: Leorize Date: Mon, 24 Sep 2018 19:08:38 +0700 Subject: [PATCH] os: add getAppFilename() implementation for Haiku --- lib/pure/os.nim | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 91d4f0f9d9..5c7d369c9e 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: "".} +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: "".} + + 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()