use realpath in a posix compliant way
This commit is contained in:
parent
f2b9af6ae1
commit
39da6979ad
1 changed files with 6 additions and 11 deletions
|
|
@ -164,7 +164,7 @@ else: # UNIX-like operating system
|
||||||
ScriptExt* = ""
|
ScriptExt* = ""
|
||||||
DynlibFormat* = when defined(macosx): "lib$1.dylib" else: "lib$1.so"
|
DynlibFormat* = when defined(macosx): "lib$1.dylib" else: "lib$1.so"
|
||||||
|
|
||||||
when defined(macosx) or defined(bsd):
|
when defined(posix):
|
||||||
var
|
var
|
||||||
pathMax {.importc: "PATH_MAX", header: "<stdlib.h>".}: cint
|
pathMax {.importc: "PATH_MAX", header: "<stdlib.h>".}: cint
|
||||||
|
|
||||||
|
|
@ -674,17 +674,12 @@ proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
|
||||||
var L = GetFullPathNameA(filename, bufsize, result, unused)
|
var L = GetFullPathNameA(filename, bufsize, result, unused)
|
||||||
if L <= 0'i32 or L >= bufsize: OSError(OSLastError())
|
if L <= 0'i32 or L >= bufsize: OSError(OSLastError())
|
||||||
setLen(result, L)
|
setLen(result, L)
|
||||||
elif defined(macosx) or defined(bsd):
|
|
||||||
# On Mac OS X 10.5, realpath does not allocate the buffer on its own
|
|
||||||
var pathBuffer: cstring = newString(pathMax)
|
|
||||||
var resultBuffer = realpath(filename, pathBuffer)
|
|
||||||
if resultBuffer == nil: OSError(OSLastError())
|
|
||||||
result = $resultBuffer
|
|
||||||
else:
|
else:
|
||||||
var res = realpath(filename, nil)
|
# careful, realpath needs to take an allocated buffer according to Posix:
|
||||||
if res == nil: OSError(OSLastError())
|
result = newString(pathMax)
|
||||||
result = $res
|
var r = realpath(filename, result)
|
||||||
c_free(res)
|
if r.isNil: OSError(OSLastError())
|
||||||
|
setlen(result, c_strlen(result))
|
||||||
|
|
||||||
proc ChangeFileExt*(filename, ext: string): string {.
|
proc ChangeFileExt*(filename, ext: string): string {.
|
||||||
noSideEffect, rtl, extern: "nos$1".} =
|
noSideEffect, rtl, extern: "nos$1".} =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue