Skip to content

Commit

Permalink
add os.absolutePath
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jul 5, 2018
1 parent a1457bf commit 79db87c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,18 @@ proc setCurrentDir*(newDir: string) {.inline, tags: [].} =
else:
if chdir(newDir) != 0'i32: raiseOSError(osLastError())

proc absolutePath*(path: string, root = getCurrentDir()):string=
## Returns the absolute path of `path`, rooted at `root`
## if `path` is absolute, return it, ignoring `root`
if isAbsolute(path): path
else: joinPath(root, path)

when isMainModule:
assert absolutePath("a", "b") == "b" / "a"
when defined(Posix):
assert absolutePath("a", "b/") == "b" / "a"
assert absolutePath("/a", "b/") == "/a"

proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
tags: [ReadDirEffect].} =
## Returns the full (`absolute`:idx:) path of the file `filename`,
Expand Down

0 comments on commit 79db87c

Please sign in to comment.