Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ proc existsDir*(dir: string): bool {.rtl, extern: "nos$1", tags: [ReadDirEffect]
## is returned. Follows symlinks.
##
## See also:
## * `checkDir proc <#checkDir,OSErrorCode>`_
## * `existsFile proc <#existsFile,string>`_
## * `symlinkExists proc <#symlinkExists,string>`_
when defined(windows):
Expand All @@ -1050,6 +1051,27 @@ proc existsDir*(dir: string): bool {.rtl, extern: "nos$1", tags: [ReadDirEffect]
var res: Stat
return stat(dir, res) >= 0'i32 and S_ISDIR(res.st_mode)

proc checkDir*(dir: string): OSErrorCode {.rtl, extern: "nos$1",
tags: [ReadDirEffect], noNimScript.} =
## Returns 0 if opening `dir` as a directory succeeds (`dir` exists and is a
## readable directory), otherwise returns the OS error code. Follows symlinks.
##
## See also:
## * `osErrorMsg proc <#osErrorMsg,OSErrorCode>`_
## * `existsDir proc <#existsDir,string>`_
## * `symlinkExists proc <#symlinkExists,string>`_
when defined(windows):
var f: WIN32_FIND_DATA
var h = findFirstFile(dir / "*", f)
defer: findClose(h)
if h == -1:
result = osLastError()
else:
var d = opendir(dir)
defer: discard closedir(d)
if d == nil:
result = osLastError()

proc symlinkExists*(link: string): bool {.rtl, extern: "nos$1",
tags: [ReadDirEffect],
noNimScript.} =
Expand Down