diff options
Diffstat (limited to 'lib/std/private/oscommon.nim')
-rw-r--r-- | lib/std/private/oscommon.nim | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/std/private/oscommon.nim b/lib/std/private/oscommon.nim index dbed1ba96..8d0df3086 100644 --- a/lib/std/private/oscommon.nim +++ b/lib/std/private/oscommon.nim @@ -1,6 +1,5 @@ include system/inclrtl -import ospaths2 import std/[oserrors] when defined(nimPreviewSlimSystem): @@ -9,6 +8,15 @@ when defined(nimPreviewSlimSystem): const weirdTarget* = defined(nimscript) or defined(js) +type + ReadDirEffect* = object of ReadIOEffect ## Effect that denotes a read + ## operation from the directory + ## structure. + WriteDirEffect* = object of WriteIOEffect ## Effect that denotes a write + ## operation to + ## the directory structure. + + when weirdTarget: discard elif defined(windows): @@ -181,3 +189,23 @@ proc symlinkExists*(link: string): bool {.rtl, extern: "nos$1", else: var res: Stat result = lstat(link, res) >= 0'i32 and S_ISLNK(res.st_mode) + +when defined(windows) and not weirdTarget: + proc openHandle*(path: string, followSymlink=true, writeAccess=false): Handle = + var flags = FILE_FLAG_BACKUP_SEMANTICS or FILE_ATTRIBUTE_NORMAL + if not followSymlink: + flags = flags or FILE_FLAG_OPEN_REPARSE_POINT + let access = if writeAccess: GENERIC_WRITE else: 0'i32 + + when useWinUnicode: + result = createFileW( + newWideCString(path), access, + FILE_SHARE_DELETE or FILE_SHARE_READ or FILE_SHARE_WRITE, + nil, OPEN_EXISTING, flags, 0 + ) + else: + result = createFileA( + path, access, + FILE_SHARE_DELETE or FILE_SHARE_READ or FILE_SHARE_WRITE, + nil, OPEN_EXISTING, flags, 0 + ) |