summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2013-09-01 22:53:02 +0200
committerAraq <rumpf_a@web.de>2013-09-01 22:53:02 +0200
commit39da6979add895cf58e9c6f883ef8df465975cd6 (patch)
tree3de7ad45950fc72403fc3c09c6a59c51dd1212f8 /lib/pure
parentf2b9af6ae15d903799d6abaf6c409bda8f829219 (diff)
downloadNim-39da6979add895cf58e9c6f883ef8df465975cd6.tar.gz
use realpath in a posix compliant way
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/os.nim17
1 files changed, 6 insertions, 11 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index 176439ec7..43bdb16ee 100644
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -164,7 +164,7 @@ else: # UNIX-like operating system
     ScriptExt* = ""
     DynlibFormat* = when defined(macosx): "lib$1.dylib" else: "lib$1.so"
 
-when defined(macosx) or defined(bsd):
+when defined(posix):
   var
     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)
       if L <= 0'i32 or L >= bufsize: OSError(OSLastError())
       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:
-    var res = realpath(filename, nil)
-    if res == nil: OSError(OSLastError())
-    result = $res
-    c_free(res)
+    # careful, realpath needs to take an allocated buffer according to Posix:
+    result = newString(pathMax)
+    var r = realpath(filename, result)
+    if r.isNil: OSError(OSLastError())
+    setlen(result, c_strlen(result))
  
 proc ChangeFileExt*(filename, ext: string): string {.
   noSideEffect, rtl, extern: "nos$1".} =