make getAppFilename work when there is no procfs
This commit is contained in:
parent
e37d72f8d4
commit
8d6ed9429a
1 changed files with 15 additions and 10 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Nimrod's Runtime Library
|
# Nimrod's Runtime Library
|
||||||
# (c) Copyright 2012 Andreas Rumpf
|
# (c) Copyright 2014 Andreas Rumpf
|
||||||
#
|
#
|
||||||
# See the file "copying.txt", included in this
|
# See the file "copying.txt", included in this
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
|
|
@ -1612,6 +1612,16 @@ when defined(linux) or defined(solaris) or defined(bsd) or defined(aix):
|
||||||
len = readlink(procPath, result, len)
|
len = readlink(procPath, result, len)
|
||||||
setLen(result, len)
|
setLen(result, len)
|
||||||
|
|
||||||
|
proc getApplHeuristic(): string =
|
||||||
|
result = string(paramStr(0))
|
||||||
|
# POSIX guaranties that this contains the executable
|
||||||
|
# as it has been executed by the calling process
|
||||||
|
if len(result) > 0 and result[0] != DirSep: # not an absolute path?
|
||||||
|
# iterate over any path in the $PATH environment variable
|
||||||
|
for p in split(string(getEnv("PATH")), {PathSep}):
|
||||||
|
var x = joinPath(p, result)
|
||||||
|
if existsFile(x): return x
|
||||||
|
|
||||||
when defined(macosx):
|
when defined(macosx):
|
||||||
type
|
type
|
||||||
cuint32* {.importc: "unsigned int", nodecl.} = int
|
cuint32* {.importc: "unsigned int", nodecl.} = int
|
||||||
|
|
@ -1648,10 +1658,13 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [FReadIO].} =
|
||||||
setlen(result, int(len))
|
setlen(result, int(len))
|
||||||
elif defined(linux) or defined(aix):
|
elif defined(linux) or defined(aix):
|
||||||
result = getApplAux("/proc/self/exe")
|
result = getApplAux("/proc/self/exe")
|
||||||
|
if result.len == 0: result = getApplHeuristic()
|
||||||
elif defined(solaris):
|
elif defined(solaris):
|
||||||
result = getApplAux("/proc/" & $getpid() & "/path/a.out")
|
result = getApplAux("/proc/" & $getpid() & "/path/a.out")
|
||||||
|
if result.len == 0: result = getApplHeuristic()
|
||||||
elif defined(freebsd):
|
elif defined(freebsd):
|
||||||
result = getApplAux("/proc/" & $getpid() & "/file")
|
result = getApplAux("/proc/" & $getpid() & "/file")
|
||||||
|
if result.len == 0: result = getApplHeuristic()
|
||||||
elif defined(macosx):
|
elif defined(macosx):
|
||||||
var size: cuint32
|
var size: cuint32
|
||||||
getExecPath1(nil, size)
|
getExecPath1(nil, size)
|
||||||
|
|
@ -1663,15 +1676,7 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [FReadIO].} =
|
||||||
else:
|
else:
|
||||||
# little heuristic that may work on other POSIX-like systems:
|
# little heuristic that may work on other POSIX-like systems:
|
||||||
result = string(getEnv("_"))
|
result = string(getEnv("_"))
|
||||||
if len(result) == 0:
|
if result.len == 0: result = getApplHeuristic()
|
||||||
result = string(paramStr(0))
|
|
||||||
# POSIX guaranties that this contains the executable
|
|
||||||
# as it has been executed by the calling process
|
|
||||||
if len(result) > 0 and result[0] != DirSep: # not an absolute path?
|
|
||||||
# iterate over any path in the $PATH environment variable
|
|
||||||
for p in split(string(getEnv("PATH")), {PathSep}):
|
|
||||||
var x = joinPath(p, result)
|
|
||||||
if existsFile(x): return x
|
|
||||||
|
|
||||||
proc getApplicationFilename*(): string {.rtl, extern: "nos$1", deprecated.} =
|
proc getApplicationFilename*(): string {.rtl, extern: "nos$1", deprecated.} =
|
||||||
## Returns the filename of the application's executable.
|
## Returns the filename of the application's executable.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue