Implements `os.expandSymlink`. Ref #3015.

This commit is contained in:
Dominik Picheta
2015-06-29 21:39:45 +01:00
parent 615defb1a9
commit 8ef0d9386b
2 changed files with 17 additions and 0 deletions

View File

@@ -1645,6 +1645,22 @@ proc getTempDir*(): string {.rtl, extern: "nos$1", tags: [ReadEnvEffect].} =
when defined(windows): return string(getEnv("TEMP")) & "\\"
else: return "/tmp/"
proc expandSymlink*(symlinkPath: string): string =
## Returns a string representing the path to which the symbolic link points.
##
## On Windows this is a noop, ``symlinkPath`` is simply returned.
when defined(windows):
result = symlinkPath
else:
result = newString(256)
var len = readlink(symlinkPath, result, 256)
if len < 0:
raiseOSError(osLastError())
if len > 256:
result = newString(len+1)
len = readlink(symlinkPath, result, len)
setLen(result, len)
when defined(nimdoc):
# Common forward declaration docstring block for parameter retrieval procs.
proc paramCount*(): int {.tags: [ReadIOEffect].} =

View File

@@ -40,6 +40,7 @@ News
- The nre module has been added, providing a better interface to PCRE than
re.
- The ``expandSymlink`` procedure has been added to the ``os`` module.
Language Additions
------------------