fixes #10066
This commit is contained in:
parent
b6257f3f21
commit
0c97d3a41c
1 changed files with 27 additions and 19 deletions
|
|
@ -19,7 +19,9 @@ include "system/inclrtl"
|
||||||
import
|
import
|
||||||
strutils, pathnorm
|
strutils, pathnorm
|
||||||
|
|
||||||
when defined(nimscript):
|
const weirdTarget = defined(nimscript) or defined(js)
|
||||||
|
|
||||||
|
when weirdTarget:
|
||||||
discard
|
discard
|
||||||
elif defined(windows):
|
elif defined(windows):
|
||||||
import winlean, times
|
import winlean, times
|
||||||
|
|
@ -31,7 +33,7 @@ elif defined(posix):
|
||||||
else:
|
else:
|
||||||
{.error: "OS module not ported to your operating system!".}
|
{.error: "OS module not ported to your operating system!".}
|
||||||
|
|
||||||
when defined(nimscript) and defined(nimErrorProcCanHaveBody):
|
when weirdTarget and defined(nimErrorProcCanHaveBody):
|
||||||
{.pragma: noNimScript, error: "this proc is not available on the NimScript target".}
|
{.pragma: noNimScript, error: "this proc is not available on the NimScript target".}
|
||||||
else:
|
else:
|
||||||
{.pragma: noNimScript.}
|
{.pragma: noNimScript.}
|
||||||
|
|
@ -662,7 +664,7 @@ when defined(windows) or defined(posix) or defined(nintendoswitch):
|
||||||
if i > 0: result.add " "
|
if i > 0: result.add " "
|
||||||
result.add quoteShell(args[i])
|
result.add quoteShell(args[i])
|
||||||
|
|
||||||
when not defined(nimscript):
|
when not weirdTarget:
|
||||||
proc c_rename(oldname, newname: cstring): cint {.
|
proc c_rename(oldname, newname: cstring): cint {.
|
||||||
importc: "rename", header: "<stdio.h>".}
|
importc: "rename", header: "<stdio.h>".}
|
||||||
proc c_system(cmd: cstring): cint {.
|
proc c_system(cmd: cstring): cint {.
|
||||||
|
|
@ -673,7 +675,7 @@ when not defined(nimscript):
|
||||||
importc: "free", header: "<stdlib.h>".}
|
importc: "free", header: "<stdlib.h>".}
|
||||||
|
|
||||||
|
|
||||||
when defined(windows) and not defined(nimscript):
|
when defined(windows) and not weirdTarget:
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
template wrapUnary(varname, winApiProc, arg: untyped) =
|
template wrapUnary(varname, winApiProc, arg: untyped) =
|
||||||
var varname = winApiProc(newWideCString(arg))
|
var varname = winApiProc(newWideCString(arg))
|
||||||
|
|
@ -755,7 +757,7 @@ proc dirExists*(dir: string): bool {.inline, noNimScript.} =
|
||||||
## Synonym for existsDir
|
## Synonym for existsDir
|
||||||
existsDir(dir)
|
existsDir(dir)
|
||||||
|
|
||||||
when not defined(windows) and not defined(nimscript):
|
when not defined(windows) and not weirdTarget:
|
||||||
proc checkSymlink(path: string): bool =
|
proc checkSymlink(path: string): bool =
|
||||||
var rawInfo: Stat
|
var rawInfo: Stat
|
||||||
if lstat(path, rawInfo) < 0'i32: result = false
|
if lstat(path, rawInfo) < 0'i32: result = false
|
||||||
|
|
@ -816,7 +818,7 @@ proc findExe*(exe: string, followSymlinks: bool = true;
|
||||||
return x
|
return x
|
||||||
result = ""
|
result = ""
|
||||||
|
|
||||||
when defined(nimscript):
|
when weirdTarget:
|
||||||
const times = "fake const"
|
const times = "fake const"
|
||||||
template Time(x: untyped): untyped = string
|
template Time(x: untyped): untyped = string
|
||||||
|
|
||||||
|
|
@ -931,7 +933,7 @@ proc setCurrentDir*(newDir: string) {.inline, tags: [], noNimScript.} =
|
||||||
else:
|
else:
|
||||||
if chdir(newDir) != 0'i32: raiseOSError(osLastError())
|
if chdir(newDir) != 0'i32: raiseOSError(osLastError())
|
||||||
|
|
||||||
when not defined(nimscript):
|
when not weirdTarget:
|
||||||
proc absolutePath*(path: string, root = getCurrentDir()): string {.noNimScript.} =
|
proc absolutePath*(path: string, root = getCurrentDir()): string {.noNimScript.} =
|
||||||
## Returns the absolute path of `path`, rooted at `root` (which must be absolute)
|
## Returns the absolute path of `path`, rooted at `root` (which must be absolute)
|
||||||
## if `path` is absolute, return it, ignoring `root`
|
## if `path` is absolute, return it, ignoring `root`
|
||||||
|
|
@ -1027,7 +1029,7 @@ proc normalizedPath*(path: string): string {.rtl, extern: "nos$1", tags: [], noN
|
||||||
## Returns a normalized path for the current OS. See `<#normalizePath>`_
|
## Returns a normalized path for the current OS. See `<#normalizePath>`_
|
||||||
result = pathnorm.normalizePath(path)
|
result = pathnorm.normalizePath(path)
|
||||||
|
|
||||||
when defined(Windows) and not defined(nimscript):
|
when defined(Windows) and not weirdTarget:
|
||||||
proc openHandle(path: string, followSymlink=true, writeAccess=false): Handle =
|
proc openHandle(path: string, followSymlink=true, writeAccess=false): Handle =
|
||||||
var flags = FILE_FLAG_BACKUP_SEMANTICS or FILE_ATTRIBUTE_NORMAL
|
var flags = FILE_FLAG_BACKUP_SEMANTICS or FILE_ATTRIBUTE_NORMAL
|
||||||
if not followSymlink:
|
if not followSymlink:
|
||||||
|
|
@ -1250,7 +1252,7 @@ when not declared(ENOENT) and not defined(Windows):
|
||||||
else:
|
else:
|
||||||
var ENOENT {.importc, header: "<errno.h>".}: cint
|
var ENOENT {.importc, header: "<errno.h>".}: cint
|
||||||
|
|
||||||
when defined(Windows) and not defined(nimscript):
|
when defined(Windows) and not weirdTarget:
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
template deleteFile(file: untyped): untyped = deleteFileW(file)
|
template deleteFile(file: untyped): untyped = deleteFileW(file)
|
||||||
template setFileAttributes(file, attrs: untyped): untyped =
|
template setFileAttributes(file, attrs: untyped): untyped =
|
||||||
|
|
@ -1343,15 +1345,15 @@ proc execShellCmd*(command: string): int {.rtl, extern: "nos$1",
|
||||||
result = c_system(command)
|
result = c_system(command)
|
||||||
|
|
||||||
# Templates for filtering directories and files
|
# Templates for filtering directories and files
|
||||||
when defined(windows) and not defined(nimscript):
|
when defined(windows) and not weirdTarget:
|
||||||
template isDir(f: WIN32_FIND_DATA): bool =
|
template isDir(f: WIN32_FIND_DATA): bool =
|
||||||
(f.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) != 0'i32
|
(f.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) != 0'i32
|
||||||
template isFile(f: WIN32_FIND_DATA): bool =
|
template isFile(f: WIN32_FIND_DATA): bool =
|
||||||
not isDir(f)
|
not isDir(f)
|
||||||
else:
|
else:
|
||||||
template isDir(f: string): bool =
|
template isDir(f: string): bool {.dirty.} =
|
||||||
dirExists(f)
|
dirExists(f)
|
||||||
template isFile(f: string): bool =
|
template isFile(f: string): bool {.dirty.} =
|
||||||
fileExists(f)
|
fileExists(f)
|
||||||
|
|
||||||
template defaultWalkFilter(item): bool =
|
template defaultWalkFilter(item): bool =
|
||||||
|
|
@ -1436,7 +1438,7 @@ proc getCurrentCompilerExe*(): string {.compileTime.} = discard
|
||||||
## inside a nimble program (likewise with other binaries built from
|
## inside a nimble program (likewise with other binaries built from
|
||||||
## compiler API).
|
## compiler API).
|
||||||
|
|
||||||
when defined(posix) and not defined(nimscript):
|
when defined(posix) and not weirdTarget:
|
||||||
proc getSymlinkFileKind(path: string): PathComponent =
|
proc getSymlinkFileKind(path: string): PathComponent =
|
||||||
# Helper function.
|
# Helper function.
|
||||||
var s: Stat
|
var s: Stat
|
||||||
|
|
@ -1477,7 +1479,7 @@ iterator walkDir*(dir: string; relative=false): tuple[kind: PathComponent, path:
|
||||||
for k, v in items(staticWalkDir(dir, relative)):
|
for k, v in items(staticWalkDir(dir, relative)):
|
||||||
yield (k, v)
|
yield (k, v)
|
||||||
else:
|
else:
|
||||||
when defined(nimscript):
|
when weirdTarget:
|
||||||
for k, v in items(staticWalkDir(dir, relative)):
|
for k, v in items(staticWalkDir(dir, relative)):
|
||||||
yield (k, v)
|
yield (k, v)
|
||||||
elif defined(windows):
|
elif defined(windows):
|
||||||
|
|
@ -1972,7 +1974,7 @@ when defined(nimdoc):
|
||||||
## else:
|
## else:
|
||||||
## # Do something else!
|
## # Do something else!
|
||||||
|
|
||||||
elif defined(nintendoswitch) or defined(nimscript):
|
elif defined(nintendoswitch) or weirdTarget:
|
||||||
proc paramStr*(i: int): TaintedString {.tags: [ReadIOEffect].} =
|
proc paramStr*(i: int): TaintedString {.tags: [ReadIOEffect].} =
|
||||||
raise newException(OSError, "paramStr is not implemented on Nintendo Switch")
|
raise newException(OSError, "paramStr is not implemented on Nintendo Switch")
|
||||||
|
|
||||||
|
|
@ -2049,7 +2051,7 @@ when declared(paramCount) or defined(nimdoc):
|
||||||
for i in 1..paramCount():
|
for i in 1..paramCount():
|
||||||
result.add(paramStr(i))
|
result.add(paramStr(i))
|
||||||
|
|
||||||
when not defined(nimscript) and (defined(freebsd) or defined(dragonfly)):
|
when not weirdTarget and (defined(freebsd) or defined(dragonfly)):
|
||||||
proc sysctl(name: ptr cint, namelen: cuint, oldp: pointer, oldplen: ptr csize,
|
proc sysctl(name: ptr cint, namelen: cuint, oldp: pointer, oldplen: ptr csize,
|
||||||
newp: pointer, newplen: csize): cint
|
newp: pointer, newplen: csize): cint
|
||||||
{.importc: "sysctl",header: """#include <sys/types.h>
|
{.importc: "sysctl",header: """#include <sys/types.h>
|
||||||
|
|
@ -2082,7 +2084,7 @@ when not defined(nimscript) and (defined(freebsd) or defined(dragonfly)):
|
||||||
result.setLen(pathLength)
|
result.setLen(pathLength)
|
||||||
break
|
break
|
||||||
|
|
||||||
when not defined(nimscript) and (defined(linux) or defined(solaris) or defined(bsd) or defined(aix)):
|
when not weirdTarget and (defined(linux) or defined(solaris) or defined(bsd) or defined(aix)):
|
||||||
proc getApplAux(procPath: string): string =
|
proc getApplAux(procPath: string): string =
|
||||||
result = newString(256)
|
result = newString(256)
|
||||||
var len = readlink(procPath, result, 256)
|
var len = readlink(procPath, result, 256)
|
||||||
|
|
@ -2091,7 +2093,7 @@ when not defined(nimscript) and (defined(linux) or defined(solaris) or defined(b
|
||||||
len = readlink(procPath, result, len)
|
len = readlink(procPath, result, len)
|
||||||
setLen(result, len)
|
setLen(result, len)
|
||||||
|
|
||||||
when not (defined(windows) or defined(macosx) or defined(nimscript)):
|
when not (defined(windows) or defined(macosx) or weirdTarget):
|
||||||
proc getApplHeuristic(): string =
|
proc getApplHeuristic(): string =
|
||||||
when declared(paramStr):
|
when declared(paramStr):
|
||||||
result = string(paramStr(0))
|
result = string(paramStr(0))
|
||||||
|
|
@ -2227,7 +2229,7 @@ proc getFileSize*(file: string): BiggestInt {.rtl, extern: "nos$1",
|
||||||
close(f)
|
close(f)
|
||||||
else: raiseOSError(osLastError())
|
else: raiseOSError(osLastError())
|
||||||
|
|
||||||
when defined(Windows) or defined(nimscript):
|
when defined(Windows) or weirdTarget:
|
||||||
type
|
type
|
||||||
DeviceId* = int32
|
DeviceId* = int32
|
||||||
FileId* = int64
|
FileId* = int64
|
||||||
|
|
@ -2307,6 +2309,12 @@ template rawToFormalFileInfo(rawInfo, path, formalInfo): untyped =
|
||||||
assert(path != "") # symlinks can't occur for file handles
|
assert(path != "") # symlinks can't occur for file handles
|
||||||
formalInfo.kind = getSymlinkFileKind(path)
|
formalInfo.kind = getSymlinkFileKind(path)
|
||||||
|
|
||||||
|
when defined(js):
|
||||||
|
when not declared(FileHandle):
|
||||||
|
type FileHandle = distinct int32
|
||||||
|
when not declared(File):
|
||||||
|
type File = object
|
||||||
|
|
||||||
proc getFileInfo*(handle: FileHandle): FileInfo {.noNimScript.} =
|
proc getFileInfo*(handle: FileHandle): FileInfo {.noNimScript.} =
|
||||||
## Retrieves file information for the file object represented by the given
|
## Retrieves file information for the file object represented by the given
|
||||||
## handle.
|
## handle.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue