stdlib: don't use deprecated symbols
This commit is contained in:
parent
e0ecaa86ba
commit
ccb9ae2d52
4 changed files with 52 additions and 52 deletions
|
|
@ -41,7 +41,7 @@ type
|
||||||
|
|
||||||
OSErrorCode* = distinct int32 ## Specifies an OS Error Code.
|
OSErrorCode* = distinct int32 ## Specifies an OS Error Code.
|
||||||
|
|
||||||
{.deprecated: [FReadEnv: ReadEnvEffect, FWriteEnv: WriteEnvEffect,
|
{.deprecated: [FReadEnv: ReadEnvEffect, FWriteEnv: WriteEnvEffect,
|
||||||
FReadDir: ReadDirEffect,
|
FReadDir: ReadDirEffect,
|
||||||
FWriteDir: WriteDirEffect,
|
FWriteDir: WriteDirEffect,
|
||||||
TOSErrorCode: OSErrorCode
|
TOSErrorCode: OSErrorCode
|
||||||
|
|
@ -359,7 +359,7 @@ when defined(windows):
|
||||||
|
|
||||||
template wrapBinary(varname, winApiProc, arg, arg2: expr) {.immediate.} =
|
template wrapBinary(varname, winApiProc, arg, arg2: expr) {.immediate.} =
|
||||||
var varname = winApiProc(newWideCString(arg), arg2)
|
var varname = winApiProc(newWideCString(arg), arg2)
|
||||||
proc findFirstFile(a: string, b: var TWIN32_FIND_DATA): Handle =
|
proc findFirstFile(a: string, b: var WIN32_FIND_DATA): Handle =
|
||||||
result = findFirstFileW(newWideCString(a), b)
|
result = findFirstFileW(newWideCString(a), b)
|
||||||
template findNextFile(a, b: expr): expr = findNextFileW(a, b)
|
template findNextFile(a, b: expr): expr = findNextFileW(a, b)
|
||||||
template getCommandLine(): expr = getCommandLineW()
|
template getCommandLine(): expr = getCommandLineW()
|
||||||
|
|
@ -373,7 +373,7 @@ when defined(windows):
|
||||||
|
|
||||||
template getFilename(f: expr): expr = $f.cFilename
|
template getFilename(f: expr): expr = $f.cFilename
|
||||||
|
|
||||||
proc skipFindData(f: TWIN32_FIND_DATA): bool {.inline.} =
|
proc skipFindData(f: WIN32_FIND_DATA): bool {.inline.} =
|
||||||
# Note - takes advantage of null delimiter in the cstring
|
# Note - takes advantage of null delimiter in the cstring
|
||||||
const dot = ord('.')
|
const dot = ord('.')
|
||||||
result = f.cFileName[0].int == dot and (f.cFileName[1].int == 0 or
|
result = f.cFileName[0].int == dot and (f.cFileName[1].int == 0 or
|
||||||
|
|
@ -437,7 +437,7 @@ proc getLastModificationTime*(file: string): Time {.rtl, extern: "nos$1".} =
|
||||||
if stat(file, res) < 0'i32: raiseOSError(osLastError())
|
if stat(file, res) < 0'i32: raiseOSError(osLastError())
|
||||||
return res.st_mtime
|
return res.st_mtime
|
||||||
else:
|
else:
|
||||||
var f: TWIN32_FIND_DATA
|
var f: WIN32_FIND_DATA
|
||||||
var h = findFirstFile(file, f)
|
var h = findFirstFile(file, f)
|
||||||
if h == -1'i32: raiseOSError(osLastError())
|
if h == -1'i32: raiseOSError(osLastError())
|
||||||
result = winTimeToUnixTime(rdFileTime(f.ftLastWriteTime))
|
result = winTimeToUnixTime(rdFileTime(f.ftLastWriteTime))
|
||||||
|
|
@ -450,7 +450,7 @@ proc getLastAccessTime*(file: string): Time {.rtl, extern: "nos$1".} =
|
||||||
if stat(file, res) < 0'i32: raiseOSError(osLastError())
|
if stat(file, res) < 0'i32: raiseOSError(osLastError())
|
||||||
return res.st_atime
|
return res.st_atime
|
||||||
else:
|
else:
|
||||||
var f: TWIN32_FIND_DATA
|
var f: WIN32_FIND_DATA
|
||||||
var h = findFirstFile(file, f)
|
var h = findFirstFile(file, f)
|
||||||
if h == -1'i32: raiseOSError(osLastError())
|
if h == -1'i32: raiseOSError(osLastError())
|
||||||
result = winTimeToUnixTime(rdFileTime(f.ftLastAccessTime))
|
result = winTimeToUnixTime(rdFileTime(f.ftLastAccessTime))
|
||||||
|
|
@ -465,7 +465,7 @@ proc getCreationTime*(file: string): Time {.rtl, extern: "nos$1".} =
|
||||||
if stat(file, res) < 0'i32: raiseOSError(osLastError())
|
if stat(file, res) < 0'i32: raiseOSError(osLastError())
|
||||||
return res.st_ctime
|
return res.st_ctime
|
||||||
else:
|
else:
|
||||||
var f: TWIN32_FIND_DATA
|
var f: WIN32_FIND_DATA
|
||||||
var h = findFirstFile(file, f)
|
var h = findFirstFile(file, f)
|
||||||
if h == -1'i32: raiseOSError(osLastError())
|
if h == -1'i32: raiseOSError(osLastError())
|
||||||
result = winTimeToUnixTime(rdFileTime(f.ftCreationTime))
|
result = winTimeToUnixTime(rdFileTime(f.ftCreationTime))
|
||||||
|
|
@ -801,13 +801,13 @@ when defined(Windows):
|
||||||
|
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
result = createFileW(
|
result = createFileW(
|
||||||
newWideCString(path), 0'i32,
|
newWideCString(path), 0'i32,
|
||||||
FILE_SHARE_DELETE or FILE_SHARE_READ or FILE_SHARE_WRITE,
|
FILE_SHARE_DELETE or FILE_SHARE_READ or FILE_SHARE_WRITE,
|
||||||
nil, OPEN_EXISTING, flags, 0
|
nil, OPEN_EXISTING, flags, 0
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
result = createFileA(
|
result = createFileA(
|
||||||
path, 0'i32,
|
path, 0'i32,
|
||||||
FILE_SHARE_DELETE or FILE_SHARE_READ or FILE_SHARE_WRITE,
|
FILE_SHARE_DELETE or FILE_SHARE_READ or FILE_SHARE_WRITE,
|
||||||
nil, OPEN_EXISTING, flags, 0
|
nil, OPEN_EXISTING, flags, 0
|
||||||
)
|
)
|
||||||
|
|
@ -827,7 +827,7 @@ proc sameFile*(path1, path2: string): bool {.rtl, extern: "nos$1",
|
||||||
|
|
||||||
var lastErr: OSErrorCode
|
var lastErr: OSErrorCode
|
||||||
if f1 != INVALID_HANDLE_VALUE and f2 != INVALID_HANDLE_VALUE:
|
if f1 != INVALID_HANDLE_VALUE and f2 != INVALID_HANDLE_VALUE:
|
||||||
var fi1, fi2: TBY_HANDLE_FILE_INFORMATION
|
var fi1, fi2: BY_HANDLE_FILE_INFORMATION
|
||||||
|
|
||||||
if getFileInformationByHandle(f1, addr(fi1)) != 0 and
|
if getFileInformationByHandle(f1, addr(fi1)) != 0 and
|
||||||
getFileInformationByHandle(f2, addr(fi2)) != 0:
|
getFileInformationByHandle(f2, addr(fi2)) != 0:
|
||||||
|
|
@ -924,11 +924,11 @@ proc getFilePermissions*(filename: string): set[FilePermission] {.
|
||||||
var res = getFileAttributesA(filename)
|
var res = getFileAttributesA(filename)
|
||||||
if res == -1'i32: raiseOSError(osLastError())
|
if res == -1'i32: raiseOSError(osLastError())
|
||||||
if (res and FILE_ATTRIBUTE_READONLY) != 0'i32:
|
if (res and FILE_ATTRIBUTE_READONLY) != 0'i32:
|
||||||
result = {fpUserExec, fpUserRead, fpGroupExec, fpGroupRead,
|
result = {fpUserExec, fpUserRead, fpGroupExec, fpGroupRead,
|
||||||
fpOthersExec, fpOthersRead}
|
fpOthersExec, fpOthersRead}
|
||||||
else:
|
else:
|
||||||
result = {fpUserExec..fpOthersRead}
|
result = {fpUserExec..fpOthersRead}
|
||||||
|
|
||||||
proc setFilePermissions*(filename: string, permissions: set[FilePermission]) {.
|
proc setFilePermissions*(filename: string, permissions: set[FilePermission]) {.
|
||||||
rtl, extern: "nos$1", tags: [WriteDirEffect].} =
|
rtl, extern: "nos$1", tags: [WriteDirEffect].} =
|
||||||
## sets the file permissions for `filename`. `OSError` is raised in case of
|
## sets the file permissions for `filename`. `OSError` is raised in case of
|
||||||
|
|
@ -939,15 +939,15 @@ proc setFilePermissions*(filename: string, permissions: set[FilePermission]) {.
|
||||||
if fpUserRead in permissions: p = p or S_IRUSR
|
if fpUserRead in permissions: p = p or S_IRUSR
|
||||||
if fpUserWrite in permissions: p = p or S_IWUSR
|
if fpUserWrite in permissions: p = p or S_IWUSR
|
||||||
if fpUserExec in permissions: p = p or S_IXUSR
|
if fpUserExec in permissions: p = p or S_IXUSR
|
||||||
|
|
||||||
if fpGroupRead in permissions: p = p or S_IRGRP
|
if fpGroupRead in permissions: p = p or S_IRGRP
|
||||||
if fpGroupWrite in permissions: p = p or S_IWGRP
|
if fpGroupWrite in permissions: p = p or S_IWGRP
|
||||||
if fpGroupExec in permissions: p = p or S_IXGRP
|
if fpGroupExec in permissions: p = p or S_IXGRP
|
||||||
|
|
||||||
if fpOthersRead in permissions: p = p or S_IROTH
|
if fpOthersRead in permissions: p = p or S_IROTH
|
||||||
if fpOthersWrite in permissions: p = p or S_IWOTH
|
if fpOthersWrite in permissions: p = p or S_IWOTH
|
||||||
if fpOthersExec in permissions: p = p or S_IXOTH
|
if fpOthersExec in permissions: p = p or S_IXOTH
|
||||||
|
|
||||||
if chmod(filename, p) != 0: raiseOSError(osLastError())
|
if chmod(filename, p) != 0: raiseOSError(osLastError())
|
||||||
else:
|
else:
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
|
|
@ -955,7 +955,7 @@ proc setFilePermissions*(filename: string, permissions: set[FilePermission]) {.
|
||||||
else:
|
else:
|
||||||
var res = getFileAttributesA(filename)
|
var res = getFileAttributesA(filename)
|
||||||
if res == -1'i32: raiseOSError(osLastError())
|
if res == -1'i32: raiseOSError(osLastError())
|
||||||
if fpUserWrite in permissions:
|
if fpUserWrite in permissions:
|
||||||
res = res and not FILE_ATTRIBUTE_READONLY
|
res = res and not FILE_ATTRIBUTE_READONLY
|
||||||
else:
|
else:
|
||||||
res = res or FILE_ATTRIBUTE_READONLY
|
res = res or FILE_ATTRIBUTE_READONLY
|
||||||
|
|
@ -1030,11 +1030,11 @@ when not declared(ENOENT) and not defined(Windows):
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
template deleteFile(file: expr): expr {.immediate.} = deleteFileW(file)
|
template deleteFile(file: expr): expr {.immediate.} = deleteFileW(file)
|
||||||
template setFileAttributes(file, attrs: expr): expr {.immediate.} =
|
template setFileAttributes(file, attrs: expr): expr {.immediate.} =
|
||||||
setFileAttributesW(file, attrs)
|
setFileAttributesW(file, attrs)
|
||||||
else:
|
else:
|
||||||
template deleteFile(file: expr): expr {.immediate.} = deleteFileA(file)
|
template deleteFile(file: expr): expr {.immediate.} = deleteFileA(file)
|
||||||
template setFileAttributes(file, attrs: expr): expr {.immediate.} =
|
template setFileAttributes(file, attrs: expr): expr {.immediate.} =
|
||||||
setFileAttributesA(file, attrs)
|
setFileAttributesA(file, attrs)
|
||||||
|
|
||||||
proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [WriteDirEffect].} =
|
proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [WriteDirEffect].} =
|
||||||
|
|
@ -1047,7 +1047,7 @@ proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [WriteDirEffect].}
|
||||||
else:
|
else:
|
||||||
let f = file
|
let f = file
|
||||||
if deleteFile(f) == 0:
|
if deleteFile(f) == 0:
|
||||||
if getLastError() == ERROR_ACCESS_DENIED:
|
if getLastError() == ERROR_ACCESS_DENIED:
|
||||||
if setFileAttributes(f, FILE_ATTRIBUTE_NORMAL) == 0:
|
if setFileAttributes(f, FILE_ATTRIBUTE_NORMAL) == 0:
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
if deleteFile(f) == 0:
|
if deleteFile(f) == 0:
|
||||||
|
|
@ -1220,7 +1220,7 @@ iterator walkFiles*(pattern: string): string {.tags: [ReadDirEffect].} =
|
||||||
## notation is supported.
|
## notation is supported.
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
var
|
var
|
||||||
f: TWIN32_FIND_DATA
|
f: WIN32_FIND_DATA
|
||||||
res: int
|
res: int
|
||||||
res = findFirstFile(pattern, f)
|
res = findFirstFile(pattern, f)
|
||||||
if res != -1:
|
if res != -1:
|
||||||
|
|
@ -1276,7 +1276,7 @@ iterator walkDir*(dir: string): tuple[kind: PathComponent, path: string] {.
|
||||||
## dirA/fileA1.txt
|
## dirA/fileA1.txt
|
||||||
## dirA/fileA2.txt
|
## dirA/fileA2.txt
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
var f: TWIN32_FIND_DATA
|
var f: WIN32_FIND_DATA
|
||||||
var h = findFirstFile(dir / "*", f)
|
var h = findFirstFile(dir / "*", f)
|
||||||
if h != -1:
|
if h != -1:
|
||||||
while true:
|
while true:
|
||||||
|
|
@ -1319,9 +1319,9 @@ iterator walkDirRec*(dir: string, filter={pcFile, pcDir}): string {.
|
||||||
## walks over the directory `dir` and yields for each file in `dir`. The
|
## walks over the directory `dir` and yields for each file in `dir`. The
|
||||||
## full path for each file is returned.
|
## full path for each file is returned.
|
||||||
## **Warning**:
|
## **Warning**:
|
||||||
## Modifying the directory structure while the iterator
|
## Modifying the directory structure while the iterator
|
||||||
## is traversing may result in undefined behavior!
|
## is traversing may result in undefined behavior!
|
||||||
##
|
##
|
||||||
## Walking is recursive. `filter` controls the behaviour of the iterator:
|
## Walking is recursive. `filter` controls the behaviour of the iterator:
|
||||||
##
|
##
|
||||||
## --------------------- ---------------------------------------------
|
## --------------------- ---------------------------------------------
|
||||||
|
|
@ -1424,7 +1424,7 @@ proc createSymlink*(src, dest: string) =
|
||||||
## by `src`. On most operating systems, will fail if a lonk
|
## by `src`. On most operating systems, will fail if a lonk
|
||||||
##
|
##
|
||||||
## **Warning**:
|
## **Warning**:
|
||||||
## Some OS's (such as Microsoft Windows) restrict the creation
|
## Some OS's (such as Microsoft Windows) restrict the creation
|
||||||
## of symlinks to root users (administrators).
|
## of symlinks to root users (administrators).
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
let flag = dirExists(src).int32
|
let flag = dirExists(src).int32
|
||||||
|
|
@ -1444,7 +1444,7 @@ proc createHardlink*(src, dest: string) =
|
||||||
## Create a hard link at `dest` which points to the item specified
|
## Create a hard link at `dest` which points to the item specified
|
||||||
## by `src`.
|
## by `src`.
|
||||||
##
|
##
|
||||||
## **Warning**: Most OS's restrict the creation of hard links to
|
## **Warning**: Most OS's restrict the creation of hard links to
|
||||||
## root users (administrators) .
|
## root users (administrators) .
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
|
|
@ -1548,7 +1548,7 @@ proc parseCmdLine*(c: string): seq[string] {.
|
||||||
add(a, c[i])
|
add(a, c[i])
|
||||||
inc(i)
|
inc(i)
|
||||||
add(result, a)
|
add(result, a)
|
||||||
|
|
||||||
proc copyFileWithPermissions*(source, dest: string,
|
proc copyFileWithPermissions*(source, dest: string,
|
||||||
ignorePermissionErrors = true) =
|
ignorePermissionErrors = true) =
|
||||||
## Copies a file from `source` to `dest` preserving file permissions.
|
## Copies a file from `source` to `dest` preserving file permissions.
|
||||||
|
|
@ -1851,7 +1851,7 @@ proc getFileSize*(file: string): BiggestInt {.rtl, extern: "nos$1",
|
||||||
tags: [ReadIOEffect].} =
|
tags: [ReadIOEffect].} =
|
||||||
## returns the file size of `file`. Can raise ``OSError``.
|
## returns the file size of `file`. Can raise ``OSError``.
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
var a: TWIN32_FIND_DATA
|
var a: WIN32_FIND_DATA
|
||||||
var resA = findFirstFile(file, a)
|
var resA = findFirstFile(file, a)
|
||||||
if resA == -1: raiseOSError(osLastError())
|
if resA == -1: raiseOSError(osLastError())
|
||||||
result = rdFileSize(a)
|
result = rdFileSize(a)
|
||||||
|
|
@ -1936,10 +1936,10 @@ template rawToFormalFileInfo(rawInfo, formalInfo): expr =
|
||||||
formalInfo.lastAccessTime = toTime(rawInfo.ftLastAccessTime)
|
formalInfo.lastAccessTime = toTime(rawInfo.ftLastAccessTime)
|
||||||
formalInfo.lastWriteTime = toTime(rawInfo.ftLastWriteTime)
|
formalInfo.lastWriteTime = toTime(rawInfo.ftLastWriteTime)
|
||||||
formalInfo.creationTime = toTime(rawInfo.ftCreationTime)
|
formalInfo.creationTime = toTime(rawInfo.ftCreationTime)
|
||||||
|
|
||||||
# Retrieve basic permissions
|
# Retrieve basic permissions
|
||||||
if (rawInfo.dwFileAttributes and FILE_ATTRIBUTE_READONLY) != 0'i32:
|
if (rawInfo.dwFileAttributes and FILE_ATTRIBUTE_READONLY) != 0'i32:
|
||||||
formalInfo.permissions = {fpUserExec, fpUserRead, fpGroupExec,
|
formalInfo.permissions = {fpUserExec, fpUserRead, fpGroupExec,
|
||||||
fpGroupRead, fpOthersExec, fpOthersRead}
|
fpGroupRead, fpOthersExec, fpOthersRead}
|
||||||
else:
|
else:
|
||||||
result.permissions = {fpUserExec..fpOthersRead}
|
result.permissions = {fpUserExec..fpOthersRead}
|
||||||
|
|
@ -1953,7 +1953,7 @@ template rawToFormalFileInfo(rawInfo, formalInfo): expr =
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
template checkAndIncludeMode(rawMode, formalMode: expr) =
|
template checkAndIncludeMode(rawMode, formalMode: expr) =
|
||||||
if (rawInfo.st_mode and rawMode) != 0'i32:
|
if (rawInfo.st_mode and rawMode) != 0'i32:
|
||||||
formalInfo.permissions.incl(formalMode)
|
formalInfo.permissions.incl(formalMode)
|
||||||
formalInfo.id = (rawInfo.st_dev, rawInfo.st_ino)
|
formalInfo.id = (rawInfo.st_dev, rawInfo.st_ino)
|
||||||
|
|
@ -1988,7 +1988,7 @@ proc getFileInfo*(handle: FileHandle): FileInfo =
|
||||||
## is invalid, an error will be thrown.
|
## is invalid, an error will be thrown.
|
||||||
# Done: ID, Kind, Size, Permissions, Link Count
|
# Done: ID, Kind, Size, Permissions, Link Count
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
var rawInfo: TBY_HANDLE_FILE_INFORMATION
|
var rawInfo: BY_HANDLE_FILE_INFORMATION
|
||||||
# We have to use the super special '_get_osfhandle' call (wrapped above)
|
# We have to use the super special '_get_osfhandle' call (wrapped above)
|
||||||
# To transform the C file descripter to a native file handle.
|
# To transform the C file descripter to a native file handle.
|
||||||
var realHandle = get_osfhandle(handle)
|
var realHandle = get_osfhandle(handle)
|
||||||
|
|
@ -2008,22 +2008,22 @@ proc getFileInfo*(file: File): FileInfo =
|
||||||
|
|
||||||
proc getFileInfo*(path: string, followSymlink = true): FileInfo =
|
proc getFileInfo*(path: string, followSymlink = true): FileInfo =
|
||||||
## Retrieves file information for the file object pointed to by `path`.
|
## Retrieves file information for the file object pointed to by `path`.
|
||||||
##
|
##
|
||||||
## Due to intrinsic differences between operating systems, the information
|
## Due to intrinsic differences between operating systems, the information
|
||||||
## contained by the returned `FileInfo` structure will be slightly different
|
## contained by the returned `FileInfo` structure will be slightly different
|
||||||
## across platforms, and in some cases, incomplete or inaccurate.
|
## across platforms, and in some cases, incomplete or inaccurate.
|
||||||
##
|
##
|
||||||
## When `followSymlink` is true, symlinks are followed and the information
|
## When `followSymlink` is true, symlinks are followed and the information
|
||||||
## retrieved is information related to the symlink's target. Otherwise,
|
## retrieved is information related to the symlink's target. Otherwise,
|
||||||
## information on the symlink itself is retrieved.
|
## information on the symlink itself is retrieved.
|
||||||
##
|
##
|
||||||
## If the information cannot be retrieved, such as when the path doesn't
|
## If the information cannot be retrieved, such as when the path doesn't
|
||||||
## exist, or when permission restrictions prevent the program from retrieving
|
## exist, or when permission restrictions prevent the program from retrieving
|
||||||
## file information, an error will be thrown.
|
## file information, an error will be thrown.
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
var
|
var
|
||||||
handle = openHandle(path, followSymlink)
|
handle = openHandle(path, followSymlink)
|
||||||
rawInfo: TBY_HANDLE_FILE_INFORMATION
|
rawInfo: BY_HANDLE_FILE_INFORMATION
|
||||||
if handle == INVALID_HANDLE_VALUE:
|
if handle == INVALID_HANDLE_VALUE:
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
if getFileInformationByHandle(handle, addr rawInfo) == 0:
|
if getFileInformationByHandle(handle, addr rawInfo) == 0:
|
||||||
|
|
@ -2044,7 +2044,7 @@ proc isHidden*(path: string): bool =
|
||||||
## Determines whether a given path is hidden or not. Returns false if the
|
## Determines whether a given path is hidden or not. Returns false if the
|
||||||
## file doesn't exist. The given path must be accessible from the current
|
## file doesn't exist. The given path must be accessible from the current
|
||||||
## working directory of the program.
|
## working directory of the program.
|
||||||
##
|
##
|
||||||
## On Windows, a file is hidden if the file's 'hidden' attribute is set.
|
## On Windows, a file is hidden if the file's 'hidden' attribute is set.
|
||||||
## On Unix-like systems, a file is hidden if it starts with a '.' (period)
|
## On Unix-like systems, a file is hidden if it starts with a '.' (period)
|
||||||
## and is not *just* '.' or '..' ' ."
|
## and is not *just* '.' or '..' ' ."
|
||||||
|
|
|
||||||
|
|
@ -396,8 +396,8 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
# O_RDONLY {.importc: "_O_RDONLY", header: "<fcntl.h>".}: int
|
# O_RDONLY {.importc: "_O_RDONLY", header: "<fcntl.h>".}: int
|
||||||
|
|
||||||
proc createPipeHandles(rdHandle, wrHandle: var Handle) =
|
proc createPipeHandles(rdHandle, wrHandle: var Handle) =
|
||||||
var piInheritablePipe: TSECURITY_ATTRIBUTES
|
var piInheritablePipe: SECURITY_ATTRIBUTES
|
||||||
piInheritablePipe.nLength = sizeof(TSECURITY_ATTRIBUTES).cint
|
piInheritablePipe.nLength = sizeof(SECURITY_ATTRIBUTES).cint
|
||||||
piInheritablePipe.lpSecurityDescriptor = nil
|
piInheritablePipe.lpSecurityDescriptor = nil
|
||||||
piInheritablePipe.bInheritHandle = 1
|
piInheritablePipe.bInheritHandle = 1
|
||||||
if createPipe(rdHandle, wrHandle, piInheritablePipe, 1024) == 0'i32:
|
if createPipe(rdHandle, wrHandle, piInheritablePipe, 1024) == 0'i32:
|
||||||
|
|
@ -412,8 +412,8 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
env: StringTableRef = nil,
|
env: StringTableRef = nil,
|
||||||
options: set[ProcessOption] = {poStdErrToStdOut}): Process =
|
options: set[ProcessOption] = {poStdErrToStdOut}): Process =
|
||||||
var
|
var
|
||||||
si: TSTARTUPINFO
|
si: STARTUPINFO
|
||||||
procInfo: TPROCESS_INFORMATION
|
procInfo: PROCESS_INFORMATION
|
||||||
success: int
|
success: int
|
||||||
hi, ho, he: Handle
|
hi, ho, he: Handle
|
||||||
new(result)
|
new(result)
|
||||||
|
|
@ -526,8 +526,8 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
|
|
||||||
proc execCmd(command: string): int =
|
proc execCmd(command: string): int =
|
||||||
var
|
var
|
||||||
si: TSTARTUPINFO
|
si: STARTUPINFO
|
||||||
procInfo: TPROCESS_INFORMATION
|
procInfo: PROCESS_INFORMATION
|
||||||
process: Handle
|
process: Handle
|
||||||
L: int32
|
L: int32
|
||||||
si.cb = sizeof(si).cint
|
si.cb = sizeof(si).cint
|
||||||
|
|
@ -555,7 +555,7 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
|
|
||||||
proc select(readfds: var seq[Process], timeout = 500): int =
|
proc select(readfds: var seq[Process], timeout = 500): int =
|
||||||
assert readfds.len <= MAXIMUM_WAIT_OBJECTS
|
assert readfds.len <= MAXIMUM_WAIT_OBJECTS
|
||||||
var rfds: TWOHandleArray
|
var rfds: WOHandleArray
|
||||||
for i in 0..readfds.len()-1:
|
for i in 0..readfds.len()-1:
|
||||||
rfds[i] = readfds[i].fProcessHandle
|
rfds[i] = readfds[i].fProcessHandle
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -470,7 +470,7 @@ when not defined(JS):
|
||||||
posix_gettimeofday(a)
|
posix_gettimeofday(a)
|
||||||
result = toFloat(a.tv_sec) + toFloat(a.tv_usec)*0.00_0001
|
result = toFloat(a.tv_sec) + toFloat(a.tv_usec)*0.00_0001
|
||||||
elif defined(windows):
|
elif defined(windows):
|
||||||
var f: winlean.TFILETIME
|
var f: winlean.FILETIME
|
||||||
getSystemTimeAsFileTime(f)
|
getSystemTimeAsFileTime(f)
|
||||||
var i64 = rdFileTime(f) - epochDiff
|
var i64 = rdFileTime(f) - epochDiff
|
||||||
var secs = i64 div rateDiff
|
var secs = i64 div rateDiff
|
||||||
|
|
|
||||||
|
|
@ -439,7 +439,7 @@ type
|
||||||
h_length*: int16
|
h_length*: int16
|
||||||
h_addr_list*: cstringArray
|
h_addr_list*: cstringArray
|
||||||
|
|
||||||
FdSet* = object
|
TFdSet* = object
|
||||||
fd_count*: cint # unsigned
|
fd_count*: cint # unsigned
|
||||||
fd_array*: array[0..FD_SETSIZE-1, SocketHandle]
|
fd_array*: array[0..FD_SETSIZE-1, SocketHandle]
|
||||||
|
|
||||||
|
|
@ -461,7 +461,7 @@ type
|
||||||
TSockAddr: SockAddr, TSockLen: SockLen, TTimeval: Timeval,
|
TSockAddr: SockAddr, TSockLen: SockLen, TTimeval: Timeval,
|
||||||
TWSADATA: WSADATA, Thostent: Hostent, TServent: Servent,
|
TWSADATA: WSADATA, Thostent: Hostent, TServent: Servent,
|
||||||
TInAddr: InAddr, Tin6_addr: In6_addr, Tsockaddr_in6: Sockaddr_in6,
|
TInAddr: InAddr, Tin6_addr: In6_addr, Tsockaddr_in6: Sockaddr_in6,
|
||||||
Tsockaddr_in6_old: Sockaddr_in6_old, TFdSet: FdSet].}
|
Tsockaddr_in6_old: Sockaddr_in6_old].}
|
||||||
|
|
||||||
|
|
||||||
var
|
var
|
||||||
|
|
@ -525,7 +525,7 @@ proc recv*(s: SocketHandle, buf: pointer, len, flags: cint): cint {.
|
||||||
proc recvfrom*(s: SocketHandle, buf: cstring, len, flags: cint,
|
proc recvfrom*(s: SocketHandle, buf: cstring, len, flags: cint,
|
||||||
fromm: ptr SockAddr, fromlen: ptr SockLen): cint {.
|
fromm: ptr SockAddr, fromlen: ptr SockLen): cint {.
|
||||||
stdcall, importc: "recvfrom", dynlib: ws2dll.}
|
stdcall, importc: "recvfrom", dynlib: ws2dll.}
|
||||||
proc select*(nfds: cint, readfds, writefds, exceptfds: ptr FdSet,
|
proc select*(nfds: cint, readfds, writefds, exceptfds: ptr TFdSet,
|
||||||
timeout: ptr Timeval): cint {.
|
timeout: ptr Timeval): cint {.
|
||||||
stdcall, importc: "select", dynlib: ws2dll.}
|
stdcall, importc: "select", dynlib: ws2dll.}
|
||||||
proc send*(s: SocketHandle, buf: pointer, len, flags: cint): cint {.
|
proc send*(s: SocketHandle, buf: pointer, len, flags: cint): cint {.
|
||||||
|
|
@ -545,18 +545,18 @@ proc getnameinfo*(a1: ptr SockAddr, a2: SockLen,
|
||||||
proc inet_addr*(cp: cstring): int32 {.
|
proc inet_addr*(cp: cstring): int32 {.
|
||||||
stdcall, importc: "inet_addr", dynlib: ws2dll.}
|
stdcall, importc: "inet_addr", dynlib: ws2dll.}
|
||||||
|
|
||||||
proc WSAFDIsSet(s: SocketHandle, set: var FdSet): bool {.
|
proc WSAFDIsSet(s: SocketHandle, set: var TFdSet): bool {.
|
||||||
stdcall, importc: "__WSAFDIsSet", dynlib: ws2dll, noSideEffect.}
|
stdcall, importc: "__WSAFDIsSet", dynlib: ws2dll, noSideEffect.}
|
||||||
|
|
||||||
proc FD_ISSET*(socket: SocketHandle, set: var FdSet): cint =
|
proc FD_ISSET*(socket: SocketHandle, set: var TFdSet): cint =
|
||||||
result = if WSAFDIsSet(socket, set): 1'i32 else: 0'i32
|
result = if WSAFDIsSet(socket, set): 1'i32 else: 0'i32
|
||||||
|
|
||||||
proc FD_SET*(socket: SocketHandle, s: var FdSet) =
|
proc FD_SET*(socket: SocketHandle, s: var TFdSet) =
|
||||||
if s.fd_count < FD_SETSIZE:
|
if s.fd_count < FD_SETSIZE:
|
||||||
s.fd_array[int(s.fd_count)] = socket
|
s.fd_array[int(s.fd_count)] = socket
|
||||||
inc(s.fd_count)
|
inc(s.fd_count)
|
||||||
|
|
||||||
proc FD_ZERO*(s: var FdSet) =
|
proc FD_ZERO*(s: var TFdSet) =
|
||||||
s.fd_count = 0
|
s.fd_count = 0
|
||||||
|
|
||||||
proc wsaStartup*(wVersionRequired: int16, WSData: ptr WSAData): cint {.
|
proc wsaStartup*(wVersionRequired: int16, WSData: ptr WSAData): cint {.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue