case consistency part 2
This commit is contained in:
parent
2df9b442c6
commit
a427648c48
9 changed files with 90 additions and 94 deletions
|
|
@ -49,7 +49,7 @@ proc parseExpr(L: var TLexer, tok: var TToken): bool =
|
||||||
var b = parseAndExpr(L, tok)
|
var b = parseAndExpr(L, tok)
|
||||||
result = result or b
|
result = result or b
|
||||||
|
|
||||||
proc EvalppIf(L: var TLexer, tok: var TToken): bool =
|
proc evalppIf(L: var TLexer, tok: var TToken): bool =
|
||||||
ppGetTok(L, tok) # skip 'if' or 'elif'
|
ppGetTok(L, tok) # skip 'if' or 'elif'
|
||||||
result = parseExpr(L, tok)
|
result = parseExpr(L, tok)
|
||||||
if tok.tokType == tkColon: ppGetTok(L, tok)
|
if tok.tokType == tkColon: ppGetTok(L, tok)
|
||||||
|
|
|
||||||
|
|
@ -273,17 +273,13 @@ proc check(c: PGen, n: PNode) =
|
||||||
nkMacroDef, nkConverterDef:
|
nkMacroDef, nkConverterDef:
|
||||||
checkDef(c, n[namePos])
|
checkDef(c, n[namePos])
|
||||||
for i in namePos+1 .. <n.len: check(c, n.sons[i])
|
for i in namePos+1 .. <n.len: check(c, n.sons[i])
|
||||||
of nkVarSection, nkLetSection:
|
of nkIdentDefs, nkVarTuple:
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
let a = n
|
||||||
let a = n.sons[i]
|
checkMinSonsLen(a, 3)
|
||||||
if a.kind == nkCommentStmt: continue
|
let L = len(a)
|
||||||
if a.kind != nkIdentDefs and a.kind != nkVarTuple:
|
for j in countup(0, L-3): checkDef(c, a.sons[j])
|
||||||
globalError(a.info, errGenerated, "invalid ast")
|
check(c, a.sons[L-2])
|
||||||
checkMinSonsLen(a, 3)
|
check(c, a.sons[L-1])
|
||||||
let L = len(a)
|
|
||||||
for j in countup(0, L-3): checkDef(c, a.sons[j])
|
|
||||||
check(c, a.sons[L-2])
|
|
||||||
check(c, a.sons[L-1])
|
|
||||||
of nkTypeSection, nkConstSection:
|
of nkTypeSection, nkConstSection:
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
let a = n.sons[i]
|
let a = n.sons[i]
|
||||||
|
|
|
||||||
|
|
@ -47,11 +47,11 @@ proc searchInstTypes*(key: PType): PType =
|
||||||
# types such as TChannel[empty]. Why?
|
# types such as TChannel[empty]. Why?
|
||||||
# See the notes for PActor in handleGenericInvokation
|
# See the notes for PActor in handleGenericInvokation
|
||||||
return
|
return
|
||||||
block MatchType:
|
block matchType:
|
||||||
for j in 1 .. high(key.sons):
|
for j in 1 .. high(key.sons):
|
||||||
# XXX sameType is not really correct for nested generics?
|
# XXX sameType is not really correct for nested generics?
|
||||||
if not sameType(inst.sons[j], key.sons[j]):
|
if not sameType(inst.sons[j], key.sons[j]):
|
||||||
break MatchType
|
break matchType
|
||||||
|
|
||||||
return inst
|
return inst
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -387,7 +387,7 @@ proc mutateType(t: PType, iter: TTypeMutator, closure: PObject): PType =
|
||||||
var marker = InitIntSet()
|
var marker = InitIntSet()
|
||||||
result = mutateTypeAux(marker, t, iter, closure)
|
result = mutateTypeAux(marker, t, iter, closure)
|
||||||
|
|
||||||
proc ValueToString(a: PNode): string =
|
proc valueToString(a: PNode): string =
|
||||||
case a.kind
|
case a.kind
|
||||||
of nkCharLit..nkUInt64Lit: result = $(a.intVal)
|
of nkCharLit..nkUInt64Lit: result = $(a.intVal)
|
||||||
of nkFloatLit..nkFloat128Lit: result = $(a.floatVal)
|
of nkFloatLit..nkFloat128Lit: result = $(a.floatVal)
|
||||||
|
|
@ -692,7 +692,7 @@ proc equalParams(a, b: PNode): TParamsEquality =
|
||||||
result = paramsIncompatible # overloading by different
|
result = paramsIncompatible # overloading by different
|
||||||
# result types does not work
|
# result types does not work
|
||||||
|
|
||||||
proc SameLiteral(x, y: PNode): bool =
|
proc sameLiteral(x, y: PNode): bool =
|
||||||
if x.kind == y.kind:
|
if x.kind == y.kind:
|
||||||
case x.kind
|
case x.kind
|
||||||
of nkCharLit..nkInt64Lit: result = x.intVal == y.intVal
|
of nkCharLit..nkInt64Lit: result = x.intVal == y.intVal
|
||||||
|
|
@ -700,7 +700,7 @@ proc SameLiteral(x, y: PNode): bool =
|
||||||
of nkNilLit: result = true
|
of nkNilLit: result = true
|
||||||
else: assert(false)
|
else: assert(false)
|
||||||
|
|
||||||
proc SameRanges(a, b: PNode): bool =
|
proc sameRanges(a, b: PNode): bool =
|
||||||
result = SameLiteral(a.sons[0], b.sons[0]) and
|
result = SameLiteral(a.sons[0], b.sons[0]) and
|
||||||
SameLiteral(a.sons[1], b.sons[1])
|
SameLiteral(a.sons[1], b.sons[1])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ proc error*(window: PWindow, msg: string) =
|
||||||
destroy(PWidget(dialog))
|
destroy(PWidget(dialog))
|
||||||
|
|
||||||
|
|
||||||
proc ChooseFileToOpen*(window: PWindow, root: string = ""): string =
|
proc chooseFileToOpen*(window: PWindow, root: string = ""): string =
|
||||||
## Opens a dialog that requests a filename from the user. Returns ""
|
## Opens a dialog that requests a filename from the user. Returns ""
|
||||||
## if the user closed the dialog without selecting a file. On Windows,
|
## if the user closed the dialog without selecting a file. On Windows,
|
||||||
## the native dialog is used, else the GTK dialog is used.
|
## the native dialog is used, else the GTK dialog is used.
|
||||||
|
|
@ -92,7 +92,7 @@ proc ChooseFileToOpen*(window: PWindow, root: string = ""): string =
|
||||||
result = ""
|
result = ""
|
||||||
destroy(PWidget(chooser))
|
destroy(PWidget(chooser))
|
||||||
|
|
||||||
proc ChooseFilesToOpen*(window: PWindow, root: string = ""): seq[string] =
|
proc chooseFilesToOpen*(window: PWindow, root: string = ""): seq[string] =
|
||||||
## Opens a dialog that requests filenames from the user. Returns ``@[]``
|
## Opens a dialog that requests filenames from the user. Returns ``@[]``
|
||||||
## if the user closed the dialog without selecting a file. On Windows,
|
## if the user closed the dialog without selecting a file. On Windows,
|
||||||
## the native dialog is used, else the GTK dialog is used.
|
## the native dialog is used, else the GTK dialog is used.
|
||||||
|
|
@ -153,7 +153,7 @@ proc ChooseFilesToOpen*(window: PWindow, root: string = ""): seq[string] =
|
||||||
destroy(PWidget(chooser))
|
destroy(PWidget(chooser))
|
||||||
|
|
||||||
|
|
||||||
proc ChooseFileToSave*(window: PWindow, root: string = ""): string =
|
proc chooseFileToSave*(window: PWindow, root: string = ""): string =
|
||||||
## Opens a dialog that requests a filename to save to from the user.
|
## Opens a dialog that requests a filename to save to from the user.
|
||||||
## Returns "" if the user closed the dialog without selecting a file.
|
## Returns "" if the user closed the dialog without selecting a file.
|
||||||
## On Windows, the native dialog is used, else the GTK dialog is used.
|
## On Windows, the native dialog is used, else the GTK dialog is used.
|
||||||
|
|
@ -190,7 +190,7 @@ proc ChooseFileToSave*(window: PWindow, root: string = ""): string =
|
||||||
destroy(PWidget(chooser))
|
destroy(PWidget(chooser))
|
||||||
|
|
||||||
|
|
||||||
proc ChooseDir*(window: PWindow, root: string = ""): string =
|
proc chooseDir*(window: PWindow, root: string = ""): string =
|
||||||
## Opens a dialog that requests a directory from the user.
|
## Opens a dialog that requests a directory from the user.
|
||||||
## Returns "" if the user closed the dialog without selecting a directory.
|
## Returns "" if the user closed the dialog without selecting a directory.
|
||||||
## On Windows, the native dialog is used, else the GTK dialog is used.
|
## On Windows, the native dialog is used, else the GTK dialog is used.
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,9 @@ proc openDefaultBrowser*(url: string) =
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
var o = newWideCString("open")
|
var o = newWideCString("open")
|
||||||
var u = newWideCString(url)
|
var u = newWideCString(url)
|
||||||
discard ShellExecuteW(0'i32, o, u, nil, nil, SW_SHOWNORMAL)
|
discard shellExecuteW(0'i32, o, u, nil, nil, SW_SHOWNORMAL)
|
||||||
else:
|
else:
|
||||||
discard ShellExecuteA(0'i32, "open", url, nil, nil, SW_SHOWNORMAL)
|
discard shellExecuteA(0'i32, "open", url, nil, nil, SW_SHOWNORMAL)
|
||||||
elif defined(macosx):
|
elif defined(macosx):
|
||||||
discard execShellCmd("open " & quoteShell(url))
|
discard execShellCmd("open " & quoteShell(url))
|
||||||
else:
|
else:
|
||||||
|
|
@ -45,4 +45,4 @@ proc openDefaultBrowser*(url: string) =
|
||||||
discard startProcess(command=b, args=[url], options={poUseShell})
|
discard startProcess(command=b, args=[url], options={poUseShell})
|
||||||
return
|
return
|
||||||
except EOS:
|
except EOS:
|
||||||
nil
|
discard
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ const
|
||||||
## The character which separates the base filename from the extension;
|
## The character which separates the base filename from the extension;
|
||||||
## for example, the '.' in ``os.nim``.
|
## for example, the '.' in ``os.nim``.
|
||||||
|
|
||||||
proc OSErrorMsg*(): string {.rtl, extern: "nos$1", deprecated.} =
|
proc osErrorMsg*(): string {.rtl, extern: "nos$1", deprecated.} =
|
||||||
## Retrieves the operating system's error flag, ``errno``.
|
## Retrieves the operating system's error flag, ``errno``.
|
||||||
## On Windows ``GetLastError`` is checked before ``errno``.
|
## On Windows ``GetLastError`` is checked before ``errno``.
|
||||||
## Returns "" if no error occured.
|
## Returns "" if no error occured.
|
||||||
|
|
@ -204,7 +204,7 @@ proc OSErrorMsg*(): string {.rtl, extern: "nos$1", deprecated.} =
|
||||||
result = $os.strerror(errno)
|
result = $os.strerror(errno)
|
||||||
|
|
||||||
{.push warning[deprecated]: off.}
|
{.push warning[deprecated]: off.}
|
||||||
proc OSError*(msg: string = "") {.noinline, rtl, extern: "nos$1", deprecated.} =
|
proc osError*(msg: string = "") {.noinline, rtl, extern: "nos$1", deprecated.} =
|
||||||
## raises an EOS exception with the given message ``msg``.
|
## raises an EOS exception with the given message ``msg``.
|
||||||
## If ``msg == ""``, the operating system's error flag
|
## If ``msg == ""``, the operating system's error flag
|
||||||
## (``errno``) is converted to a readable error message. On Windows
|
## (``errno``) is converted to a readable error message. On Windows
|
||||||
|
|
@ -213,7 +213,7 @@ proc OSError*(msg: string = "") {.noinline, rtl, extern: "nos$1", deprecated.} =
|
||||||
##
|
##
|
||||||
## **Deprecated since version 0.9.4**: use the other ``OSError`` proc.
|
## **Deprecated since version 0.9.4**: use the other ``OSError`` proc.
|
||||||
if len(msg) == 0:
|
if len(msg) == 0:
|
||||||
var m = OSErrorMsg()
|
var m = osErrorMsg()
|
||||||
raise newException(EOS, if m.len > 0: m else: "unknown OS error")
|
raise newException(EOS, if m.len > 0: m else: "unknown OS error")
|
||||||
else:
|
else:
|
||||||
raise newException(EOS, msg)
|
raise newException(EOS, msg)
|
||||||
|
|
@ -222,7 +222,7 @@ proc OSError*(msg: string = "") {.noinline, rtl, extern: "nos$1", deprecated.} =
|
||||||
proc `==`*(err1, err2: TOSErrorCode): bool {.borrow.}
|
proc `==`*(err1, err2: TOSErrorCode): bool {.borrow.}
|
||||||
proc `$`*(err: TOSErrorCode): string {.borrow.}
|
proc `$`*(err: TOSErrorCode): string {.borrow.}
|
||||||
|
|
||||||
proc OSErrorMsg*(errorCode: TOSErrorCode): string =
|
proc osErrorMsg*(errorCode: TOSErrorCode): string =
|
||||||
## Converts an OS error code into a human readable string.
|
## Converts an OS error code into a human readable string.
|
||||||
##
|
##
|
||||||
## The error code can be retrieved using the ``OSLastError`` proc.
|
## The error code can be retrieved using the ``OSLastError`` proc.
|
||||||
|
|
@ -252,7 +252,7 @@ proc OSErrorMsg*(errorCode: TOSErrorCode): string =
|
||||||
if errorCode != TOSErrorCode(0'i32):
|
if errorCode != TOSErrorCode(0'i32):
|
||||||
result = $os.strerror(errorCode.int32)
|
result = $os.strerror(errorCode.int32)
|
||||||
|
|
||||||
proc OSError*(errorCode: TOSErrorCode) =
|
proc osError*(errorCode: TOSErrorCode) =
|
||||||
## Raises an ``EOS`` exception. The ``errorCode`` will determine the
|
## Raises an ``EOS`` exception. The ``errorCode`` will determine the
|
||||||
## message, ``OSErrorMsg`` will be used to get this message.
|
## message, ``OSErrorMsg`` will be used to get this message.
|
||||||
##
|
##
|
||||||
|
|
@ -260,14 +260,14 @@ proc OSError*(errorCode: TOSErrorCode) =
|
||||||
##
|
##
|
||||||
## If the error code is ``0`` or an error message could not be retrieved,
|
## If the error code is ``0`` or an error message could not be retrieved,
|
||||||
## the message ``unknown OS error`` will be used.
|
## the message ``unknown OS error`` will be used.
|
||||||
let msg = OSErrorMsg(errorCode)
|
let msg = osErrorMsg(errorCode)
|
||||||
if msg == "":
|
if msg == "":
|
||||||
raise newException(EOS, "unknown OS error")
|
raise newException(EOS, "unknown OS error")
|
||||||
else:
|
else:
|
||||||
raise newException(EOS, msg)
|
raise newException(EOS, msg)
|
||||||
|
|
||||||
{.push stackTrace:off.}
|
{.push stackTrace:off.}
|
||||||
proc OSLastError*(): TOSErrorCode =
|
proc osLastError*(): TOSErrorCode =
|
||||||
## Retrieves the last operating system error code.
|
## Retrieves the last operating system error code.
|
||||||
##
|
##
|
||||||
## This procedure is useful in the event when an OS call fails. In that case
|
## This procedure is useful in the event when an OS call fails. In that case
|
||||||
|
|
@ -391,12 +391,12 @@ proc getLastModificationTime*(file: string): TTime {.rtl, extern: "nos$1".} =
|
||||||
## Returns the `file`'s last modification time.
|
## Returns the `file`'s last modification time.
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
var res: TStat
|
var res: TStat
|
||||||
if stat(file, res) < 0'i32: OSError(OSLastError())
|
if stat(file, res) < 0'i32: osError(osLastError())
|
||||||
return res.st_mtime
|
return res.st_mtime
|
||||||
else:
|
else:
|
||||||
var f: TWIN32_Find_Data
|
var f: TWIN32_Find_Data
|
||||||
var h = findFirstFile(file, f)
|
var h = findFirstFile(file, f)
|
||||||
if h == -1'i32: OSError(OSLastError())
|
if h == -1'i32: osError(osLastError())
|
||||||
result = winTimeToUnixTime(rdFileTime(f.ftLastWriteTime))
|
result = winTimeToUnixTime(rdFileTime(f.ftLastWriteTime))
|
||||||
findclose(h)
|
findclose(h)
|
||||||
|
|
||||||
|
|
@ -404,12 +404,12 @@ proc getLastAccessTime*(file: string): TTime {.rtl, extern: "nos$1".} =
|
||||||
## Returns the `file`'s last read or write access time.
|
## Returns the `file`'s last read or write access time.
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
var res: TStat
|
var res: TStat
|
||||||
if stat(file, res) < 0'i32: OSError(OSLastError())
|
if stat(file, res) < 0'i32: osError(osLastError())
|
||||||
return res.st_atime
|
return res.st_atime
|
||||||
else:
|
else:
|
||||||
var f: TWIN32_Find_Data
|
var f: TWIN32_Find_Data
|
||||||
var h = findFirstFile(file, f)
|
var h = findFirstFile(file, f)
|
||||||
if h == -1'i32: OSError(OSLastError())
|
if h == -1'i32: osError(osLastError())
|
||||||
result = winTimeToUnixTime(rdFileTime(f.ftLastAccessTime))
|
result = winTimeToUnixTime(rdFileTime(f.ftLastAccessTime))
|
||||||
findclose(h)
|
findclose(h)
|
||||||
|
|
||||||
|
|
@ -417,12 +417,12 @@ proc getCreationTime*(file: string): TTime {.rtl, extern: "nos$1".} =
|
||||||
## Returns the `file`'s creation time.
|
## Returns the `file`'s creation time.
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
var res: TStat
|
var res: TStat
|
||||||
if stat(file, res) < 0'i32: OSError(OSLastError())
|
if stat(file, res) < 0'i32: osError(osLastError())
|
||||||
return res.st_ctime
|
return res.st_ctime
|
||||||
else:
|
else:
|
||||||
var f: TWIN32_Find_Data
|
var f: TWIN32_Find_Data
|
||||||
var h = findFirstFile(file, f)
|
var h = findFirstFile(file, f)
|
||||||
if h == -1'i32: OSError(OSLastError())
|
if h == -1'i32: osError(osLastError())
|
||||||
result = winTimeToUnixTime(rdFileTime(f.ftCreationTime))
|
result = winTimeToUnixTime(rdFileTime(f.ftCreationTime))
|
||||||
findclose(h)
|
findclose(h)
|
||||||
|
|
||||||
|
|
@ -438,19 +438,19 @@ proc getCurrentDir*(): string {.rtl, extern: "nos$1", tags: [].} =
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
var res = newWideCString("", bufsize)
|
var res = newWideCString("", bufsize)
|
||||||
var L = getCurrentDirectoryW(bufsize, res)
|
var L = getCurrentDirectoryW(bufsize, res)
|
||||||
if L == 0'i32: OSError(OSLastError())
|
if L == 0'i32: osError(osLastError())
|
||||||
result = res$L
|
result = res$L
|
||||||
else:
|
else:
|
||||||
result = newString(bufsize)
|
result = newString(bufsize)
|
||||||
var L = getCurrentDirectoryA(bufsize, result)
|
var L = getCurrentDirectoryA(bufsize, result)
|
||||||
if L == 0'i32: OSError(OSLastError())
|
if L == 0'i32: osError(osLastError())
|
||||||
setLen(result, L)
|
setLen(result, L)
|
||||||
else:
|
else:
|
||||||
result = newString(bufsize)
|
result = newString(bufsize)
|
||||||
if getcwd(result, bufsize) != nil:
|
if getcwd(result, bufsize) != nil:
|
||||||
setlen(result, c_strlen(result))
|
setlen(result, c_strlen(result))
|
||||||
else:
|
else:
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
|
|
||||||
proc setCurrentDir*(newDir: string) {.inline, tags: [].} =
|
proc setCurrentDir*(newDir: string) {.inline, tags: [].} =
|
||||||
## Sets the `current working directory`:idx:; `EOS` is raised if
|
## Sets the `current working directory`:idx:; `EOS` is raised if
|
||||||
|
|
@ -458,11 +458,11 @@ proc setCurrentDir*(newDir: string) {.inline, tags: [].} =
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
if setCurrentDirectoryW(newWideCString(newDir)) == 0'i32:
|
if setCurrentDirectoryW(newWideCString(newDir)) == 0'i32:
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
else:
|
else:
|
||||||
if setCurrentDirectoryA(newDir) == 0'i32: OSError(OSLastError())
|
if setCurrentDirectoryA(newDir) == 0'i32: osError(osLastError())
|
||||||
else:
|
else:
|
||||||
if chdir(newDir) != 0'i32: OSError(OSLastError())
|
if chdir(newDir) != 0'i32: osError(osLastError())
|
||||||
|
|
||||||
proc joinPath*(head, tail: string): string {.
|
proc joinPath*(head, tail: string): string {.
|
||||||
noSideEffect, rtl, extern: "nos$1".} =
|
noSideEffect, rtl, extern: "nos$1".} =
|
||||||
|
|
@ -674,19 +674,19 @@ proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
|
||||||
var res = newWideCString("", bufsize div 2)
|
var res = newWideCString("", bufsize div 2)
|
||||||
var L = getFullPathNameW(newWideCString(filename), bufsize, res, unused)
|
var L = getFullPathNameW(newWideCString(filename), bufsize, res, unused)
|
||||||
if L <= 0'i32 or L >= bufsize:
|
if L <= 0'i32 or L >= bufsize:
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
result = res$L
|
result = res$L
|
||||||
else:
|
else:
|
||||||
var unused: cstring
|
var unused: cstring
|
||||||
result = newString(bufsize)
|
result = newString(bufsize)
|
||||||
var L = getFullPathNameA(filename, bufsize, result, unused)
|
var L = getFullPathNameA(filename, bufsize, result, unused)
|
||||||
if L <= 0'i32 or L >= bufsize: OSError(OSLastError())
|
if L <= 0'i32 or L >= bufsize: osError(osLastError())
|
||||||
setLen(result, L)
|
setLen(result, L)
|
||||||
else:
|
else:
|
||||||
# careful, realpath needs to take an allocated buffer according to Posix:
|
# careful, realpath needs to take an allocated buffer according to Posix:
|
||||||
result = newString(pathMax)
|
result = newString(pathMax)
|
||||||
var r = realpath(filename, result)
|
var r = realpath(filename, result)
|
||||||
if r.isNil: OSError(OSLastError())
|
if r.isNil: osError(osLastError())
|
||||||
setlen(result, c_strlen(result))
|
setlen(result, c_strlen(result))
|
||||||
|
|
||||||
proc changeFileExt*(filename, ext: string): string {.
|
proc changeFileExt*(filename, ext: string): string {.
|
||||||
|
|
@ -785,20 +785,20 @@ proc sameFile*(path1, path2: string): bool {.rtl, extern: "nos$1",
|
||||||
fi1.nFileIndexHigh == fi2.nFileIndexHigh and
|
fi1.nFileIndexHigh == fi2.nFileIndexHigh and
|
||||||
fi1.nFileIndexLow == fi2.nFileIndexLow
|
fi1.nFileIndexLow == fi2.nFileIndexLow
|
||||||
else:
|
else:
|
||||||
lastErr = OSLastError()
|
lastErr = osLastError()
|
||||||
success = false
|
success = false
|
||||||
else:
|
else:
|
||||||
lastErr = OSLastError()
|
lastErr = osLastError()
|
||||||
success = false
|
success = false
|
||||||
|
|
||||||
discard closeHandle(f1)
|
discard closeHandle(f1)
|
||||||
discard closeHandle(f2)
|
discard closeHandle(f2)
|
||||||
|
|
||||||
if not success: OSError(lastErr)
|
if not success: osError(lastErr)
|
||||||
else:
|
else:
|
||||||
var a, b: TStat
|
var a, b: TStat
|
||||||
if stat(path1, a) < 0'i32 or stat(path2, b) < 0'i32:
|
if stat(path1, a) < 0'i32 or stat(path2, b) < 0'i32:
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
else:
|
else:
|
||||||
result = a.st_dev == b.st_dev and a.st_ino == b.st_ino
|
result = a.st_dev == b.st_dev and a.st_ino == b.st_ino
|
||||||
|
|
||||||
|
|
@ -852,7 +852,7 @@ proc getFilePermissions*(filename: string): set[TFilePermission] {.
|
||||||
## permission is available in any case.
|
## permission is available in any case.
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
var a: TStat
|
var a: TStat
|
||||||
if stat(filename, a) < 0'i32: OSError(OSLastError())
|
if stat(filename, a) < 0'i32: osError(osLastError())
|
||||||
result = {}
|
result = {}
|
||||||
if (a.st_mode and S_IRUSR) != 0'i32: result.incl(fpUserRead)
|
if (a.st_mode and S_IRUSR) != 0'i32: result.incl(fpUserRead)
|
||||||
if (a.st_mode and S_IWUSR) != 0'i32: result.incl(fpUserWrite)
|
if (a.st_mode and S_IWUSR) != 0'i32: result.incl(fpUserWrite)
|
||||||
|
|
@ -870,7 +870,7 @@ proc getFilePermissions*(filename: string): set[TFilePermission] {.
|
||||||
wrapUnary(res, getFileAttributesW, filename)
|
wrapUnary(res, getFileAttributesW, filename)
|
||||||
else:
|
else:
|
||||||
var res = getFileAttributesA(filename)
|
var res = getFileAttributesA(filename)
|
||||||
if res == -1'i32: OSError(OSLastError())
|
if res == -1'i32: osError(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}
|
||||||
|
|
@ -896,13 +896,13 @@ proc setFilePermissions*(filename: string, permissions: set[TFilePermission]) {.
|
||||||
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: OSError(OSLastError())
|
if chmod(filename, p) != 0: osError(osLastError())
|
||||||
else:
|
else:
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
wrapUnary(res, getFileAttributesW, filename)
|
wrapUnary(res, getFileAttributesW, filename)
|
||||||
else:
|
else:
|
||||||
var res = getFileAttributesA(filename)
|
var res = getFileAttributesA(filename)
|
||||||
if res == -1'i32: OSError(OSLastError())
|
if res == -1'i32: osError(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:
|
||||||
|
|
@ -911,7 +911,7 @@ proc setFilePermissions*(filename: string, permissions: set[TFilePermission]) {.
|
||||||
wrapBinary(res2, setFileAttributesW, filename, res)
|
wrapBinary(res2, setFileAttributesW, filename, res)
|
||||||
else:
|
else:
|
||||||
var res2 = setFileAttributesA(filename, res)
|
var res2 = setFileAttributesA(filename, res)
|
||||||
if res2 == - 1'i32: OSError(OSLastError())
|
if res2 == - 1'i32: osError(osLastError())
|
||||||
|
|
||||||
proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||||
tags: [FReadIO, FWriteIO].} =
|
tags: [FReadIO, FWriteIO].} =
|
||||||
|
|
@ -928,17 +928,17 @@ proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
let s = newWideCString(source)
|
let s = newWideCString(source)
|
||||||
let d = newWideCString(dest)
|
let d = newWideCString(dest)
|
||||||
if copyFileW(s, d, 0'i32) == 0'i32: OSError(OSLastError())
|
if copyFileW(s, d, 0'i32) == 0'i32: osError(osLastError())
|
||||||
else:
|
else:
|
||||||
if copyFileA(source, dest, 0'i32) == 0'i32: OSError(OSLastError())
|
if copyFileA(source, dest, 0'i32) == 0'i32: osError(osLastError())
|
||||||
else:
|
else:
|
||||||
# generic version of copyFile which works for any platform:
|
# generic version of copyFile which works for any platform:
|
||||||
const bufSize = 8000 # better for memory manager
|
const bufSize = 8000 # better for memory manager
|
||||||
var d, s: TFile
|
var d, s: TFile
|
||||||
if not open(s, source): OSError(OSLastError())
|
if not open(s, source): osError(osLastError())
|
||||||
if not open(d, dest, fmWrite):
|
if not open(d, dest, fmWrite):
|
||||||
close(s)
|
close(s)
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
var buf = alloc(bufsize)
|
var buf = alloc(bufsize)
|
||||||
while true:
|
while true:
|
||||||
var bytesread = readBuffer(s, buf, bufsize)
|
var bytesread = readBuffer(s, buf, bufsize)
|
||||||
|
|
@ -948,7 +948,7 @@ proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||||
dealloc(buf)
|
dealloc(buf)
|
||||||
close(s)
|
close(s)
|
||||||
close(d)
|
close(d)
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
if bytesread != bufSize: break
|
if bytesread != bufSize: break
|
||||||
dealloc(buf)
|
dealloc(buf)
|
||||||
close(s)
|
close(s)
|
||||||
|
|
@ -988,9 +988,9 @@ proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} =
|
||||||
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:
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
if deleteFile(f) == 0:
|
if deleteFile(f) == 0:
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
else:
|
else:
|
||||||
if cremove(file) != 0'i32 and errno != ENOENT:
|
if cremove(file) != 0'i32 and errno != ENOENT:
|
||||||
raise newException(EOS, $strerror(errno))
|
raise newException(EOS, $strerror(errno))
|
||||||
|
|
@ -1125,14 +1125,14 @@ proc putEnv*(key, val: string) {.tags: [FWriteEnv].} =
|
||||||
indx = high(environment)
|
indx = high(environment)
|
||||||
when defined(unix):
|
when defined(unix):
|
||||||
if cputenv(environment[indx]) != 0'i32:
|
if cputenv(environment[indx]) != 0'i32:
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
else:
|
else:
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
var k = newWideCString(key)
|
var k = newWideCString(key)
|
||||||
var v = newWideCString(val)
|
var v = newWideCString(val)
|
||||||
if setEnvironmentVariableW(k, v) == 0'i32: OSError(OSLastError())
|
if setEnvironmentVariableW(k, v) == 0'i32: osError(osLastError())
|
||||||
else:
|
else:
|
||||||
if setEnvironmentVariableA(key, val) == 0'i32: OSError(OSLastError())
|
if setEnvironmentVariableA(key, val) == 0'i32: osError(osLastError())
|
||||||
|
|
||||||
iterator envPairs*(): tuple[key, value: TaintedString] {.tags: [FReadEnv].} =
|
iterator envPairs*(): tuple[key, value: TaintedString] {.tags: [FReadEnv].} =
|
||||||
## Iterate over all `environments variables`:idx:. In the first component
|
## Iterate over all `environments variables`:idx:. In the first component
|
||||||
|
|
@ -1262,12 +1262,12 @@ proc rawRemoveDir(dir: string) =
|
||||||
wrapUnary(res, removeDirectoryW, dir)
|
wrapUnary(res, removeDirectoryW, dir)
|
||||||
else:
|
else:
|
||||||
var res = removeDirectoryA(dir)
|
var res = removeDirectoryA(dir)
|
||||||
let lastError = OSLastError()
|
let lastError = osLastError()
|
||||||
if res == 0'i32 and lastError.int32 != 3'i32 and
|
if res == 0'i32 and lastError.int32 != 3'i32 and
|
||||||
lastError.int32 != 18'i32 and lastError.int32 != 2'i32:
|
lastError.int32 != 18'i32 and lastError.int32 != 2'i32:
|
||||||
OSError(lastError)
|
osError(lastError)
|
||||||
else:
|
else:
|
||||||
if rmdir(dir) != 0'i32 and errno != ENOENT: OSError(OSLastError())
|
if rmdir(dir) != 0'i32 and errno != ENOENT: osError(osLastError())
|
||||||
|
|
||||||
proc removeDir*(dir: string) {.rtl, extern: "nos$1", tags: [
|
proc removeDir*(dir: string) {.rtl, extern: "nos$1", tags: [
|
||||||
FWriteDir, FReadDir].} =
|
FWriteDir, FReadDir].} =
|
||||||
|
|
@ -1285,17 +1285,17 @@ proc removeDir*(dir: string) {.rtl, extern: "nos$1", tags: [
|
||||||
proc rawCreateDir(dir: string) =
|
proc rawCreateDir(dir: string) =
|
||||||
when defined(solaris):
|
when defined(solaris):
|
||||||
if mkdir(dir, 0o711) != 0'i32 and errno != EEXIST and errno != ENOSYS:
|
if mkdir(dir, 0o711) != 0'i32 and errno != EEXIST and errno != ENOSYS:
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
elif defined(unix):
|
elif defined(unix):
|
||||||
if mkdir(dir, 0o711) != 0'i32 and errno != EEXIST:
|
if mkdir(dir, 0o711) != 0'i32 and errno != EEXIST:
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
else:
|
else:
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
wrapUnary(res, createDirectoryW, dir)
|
wrapUnary(res, createDirectoryW, dir)
|
||||||
else:
|
else:
|
||||||
var res = createDirectoryA(dir)
|
var res = createDirectoryA(dir)
|
||||||
if res == 0'i32 and getLastError() != 183'i32:
|
if res == 0'i32 and getLastError() != 183'i32:
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
|
|
||||||
proc createDir*(dir: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} =
|
proc createDir*(dir: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} =
|
||||||
## Creates the `directory`:idx: `dir`.
|
## Creates the `directory`:idx: `dir`.
|
||||||
|
|
@ -1620,7 +1620,7 @@ proc getFileSize*(file: string): biggestInt {.rtl, extern: "nos$1",
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
var a: TWin32FindData
|
var a: TWin32FindData
|
||||||
var resA = findfirstFile(file, a)
|
var resA = findfirstFile(file, a)
|
||||||
if resA == -1: OSError(OSLastError())
|
if resA == -1: osError(osLastError())
|
||||||
result = rdFileSize(a)
|
result = rdFileSize(a)
|
||||||
findclose(resA)
|
findclose(resA)
|
||||||
else:
|
else:
|
||||||
|
|
@ -1628,7 +1628,7 @@ proc getFileSize*(file: string): biggestInt {.rtl, extern: "nos$1",
|
||||||
if open(f, file):
|
if open(f, file):
|
||||||
result = getFileSize(f)
|
result = getFileSize(f)
|
||||||
close(f)
|
close(f)
|
||||||
else: OSError(OSLastError())
|
else: osError(osLastError())
|
||||||
|
|
||||||
proc findExe*(exe: string): string {.tags: [FReadDir, FReadEnv].} =
|
proc findExe*(exe: string): string {.tags: [FReadDir, FReadEnv].} =
|
||||||
## Searches for `exe` in the current working directory and then
|
## Searches for `exe` in the current working directory and then
|
||||||
|
|
|
||||||
|
|
@ -340,7 +340,7 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
# TRUE and zero bytes returned (EOF).
|
# TRUE and zero bytes returned (EOF).
|
||||||
# TRUE and n (>0) bytes returned (good data).
|
# TRUE and n (>0) bytes returned (good data).
|
||||||
# FALSE and bytes returned undefined (system error).
|
# FALSE and bytes returned undefined (system error).
|
||||||
if a == 0 and br != 0: OSError(OSLastError())
|
if a == 0 and br != 0: osError(osLastError())
|
||||||
s.atTheEnd = br < bufLen
|
s.atTheEnd = br < bufLen
|
||||||
result = br
|
result = br
|
||||||
|
|
||||||
|
|
@ -348,7 +348,7 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
var s = PFileHandleStream(s)
|
var s = PFileHandleStream(s)
|
||||||
var bytesWritten: int32
|
var bytesWritten: int32
|
||||||
var a = winlean.writeFile(s.handle, buffer, bufLen.cint, bytesWritten, nil)
|
var a = winlean.writeFile(s.handle, buffer, bufLen.cint, bytesWritten, nil)
|
||||||
if a == 0: OSError(OSLastError())
|
if a == 0: osError(osLastError())
|
||||||
|
|
||||||
proc newFileHandleStream(handle: THandle): PFileHandleStream =
|
proc newFileHandleStream(handle: THandle): PFileHandleStream =
|
||||||
new(result)
|
new(result)
|
||||||
|
|
@ -389,7 +389,7 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
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:
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
|
|
||||||
proc fileClose(h: THandle) {.inline.} =
|
proc fileClose(h: THandle) {.inline.} =
|
||||||
if h > 4: discard closeHandle(h)
|
if h > 4: discard closeHandle(h)
|
||||||
|
|
@ -446,7 +446,7 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
else:
|
else:
|
||||||
success = winlean.CreateProcessA(nil,
|
success = winlean.CreateProcessA(nil,
|
||||||
cmdl, nil, nil, 1, NORMAL_PRIORITY_CLASS, e, wd, SI, ProcInfo)
|
cmdl, nil, nil, 1, NORMAL_PRIORITY_CLASS, e, wd, SI, ProcInfo)
|
||||||
let lastError = OSLastError()
|
let lastError = osLastError()
|
||||||
|
|
||||||
if poParentStreams notin options:
|
if poParentStreams notin options:
|
||||||
FileClose(si.hStdInput)
|
FileClose(si.hStdInput)
|
||||||
|
|
@ -456,7 +456,7 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
|
|
||||||
if e != nil: dealloc(e)
|
if e != nil: dealloc(e)
|
||||||
dealloc(cmdl)
|
dealloc(cmdl)
|
||||||
if success == 0: OSError(lastError)
|
if success == 0: osError(lastError)
|
||||||
# Close the handle now so anyone waiting is woken:
|
# Close the handle now so anyone waiting is woken:
|
||||||
discard closeHandle(procInfo.hThread)
|
discard closeHandle(procInfo.hThread)
|
||||||
result.FProcessHandle = procInfo.hProcess
|
result.FProcessHandle = procInfo.hProcess
|
||||||
|
|
@ -527,7 +527,7 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
var res = winlean.CreateProcessA(nil, command, nil, nil, 0,
|
var res = winlean.CreateProcessA(nil, command, nil, nil, 0,
|
||||||
NORMAL_PRIORITY_CLASS, nil, nil, SI, ProcInfo)
|
NORMAL_PRIORITY_CLASS, nil, nil, SI, ProcInfo)
|
||||||
if res == 0:
|
if res == 0:
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
else:
|
else:
|
||||||
Process = ProcInfo.hProcess
|
Process = ProcInfo.hProcess
|
||||||
discard CloseHandle(ProcInfo.hThread)
|
discard CloseHandle(ProcInfo.hThread)
|
||||||
|
|
@ -550,7 +550,7 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
of WAIT_TIMEOUT:
|
of WAIT_TIMEOUT:
|
||||||
return 0
|
return 0
|
||||||
of WAIT_FAILED:
|
of WAIT_FAILED:
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
else:
|
else:
|
||||||
var i = ret - WAIT_OBJECT_0
|
var i = ret - WAIT_OBJECT_0
|
||||||
readfds.del(i)
|
readfds.del(i)
|
||||||
|
|
@ -608,7 +608,7 @@ elif not defined(useNimRtl):
|
||||||
if poParentStreams notin options:
|
if poParentStreams notin options:
|
||||||
if pipe(p_stdin) != 0'i32 or pipe(p_stdout) != 0'i32 or
|
if pipe(p_stdin) != 0'i32 or pipe(p_stdout) != 0'i32 or
|
||||||
pipe(p_stderr) != 0'i32:
|
pipe(p_stderr) != 0'i32:
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
|
|
||||||
var pid: TPid
|
var pid: TPid
|
||||||
when defined(posix_spawn) and not defined(useFork):
|
when defined(posix_spawn) and not defined(useFork):
|
||||||
|
|
@ -616,7 +616,7 @@ elif not defined(useNimRtl):
|
||||||
var fops: Tposix_spawn_file_actions
|
var fops: Tposix_spawn_file_actions
|
||||||
|
|
||||||
template chck(e: expr) =
|
template chck(e: expr) =
|
||||||
if e != 0'i32: OSError(OSLastError())
|
if e != 0'i32: osError(osLastError())
|
||||||
|
|
||||||
chck posix_spawn_file_actions_init(fops)
|
chck posix_spawn_file_actions_init(fops)
|
||||||
chck posix_spawnattr_init(attr)
|
chck posix_spawnattr_init(attr)
|
||||||
|
|
@ -661,20 +661,20 @@ elif not defined(useNimRtl):
|
||||||
else:
|
else:
|
||||||
|
|
||||||
Pid = fork()
|
Pid = fork()
|
||||||
if Pid < 0: OSError(OSLastError())
|
if Pid < 0: osError(osLastError())
|
||||||
if pid == 0:
|
if pid == 0:
|
||||||
## child process:
|
## child process:
|
||||||
|
|
||||||
if poParentStreams notin options:
|
if poParentStreams notin options:
|
||||||
discard close(p_stdin[writeIdx])
|
discard close(p_stdin[writeIdx])
|
||||||
if dup2(p_stdin[readIdx], readIdx) < 0: OSError(OSLastError())
|
if dup2(p_stdin[readIdx], readIdx) < 0: osError(osLastError())
|
||||||
discard close(p_stdout[readIdx])
|
discard close(p_stdout[readIdx])
|
||||||
if dup2(p_stdout[writeIdx], writeIdx) < 0: OSError(OSLastError())
|
if dup2(p_stdout[writeIdx], writeIdx) < 0: osError(osLastError())
|
||||||
discard close(p_stderr[readIdx])
|
discard close(p_stderr[readIdx])
|
||||||
if poStdErrToStdOut in options:
|
if poStdErrToStdOut in options:
|
||||||
if dup2(p_stdout[writeIdx], 2) < 0: OSError(OSLastError())
|
if dup2(p_stdout[writeIdx], 2) < 0: osError(osLastError())
|
||||||
else:
|
else:
|
||||||
if dup2(p_stderr[writeIdx], 2) < 0: OSError(OSLastError())
|
if dup2(p_stderr[writeIdx], 2) < 0: osError(osLastError())
|
||||||
|
|
||||||
# Create a new process group
|
# Create a new process group
|
||||||
if setpgid(0, 0) == -1: quit("setpgid call failed: " & $strerror(errno))
|
if setpgid(0, 0) == -1: quit("setpgid call failed: " & $strerror(errno))
|
||||||
|
|
@ -729,10 +729,10 @@ elif not defined(useNimRtl):
|
||||||
discard close(p.errHandle)
|
discard close(p.errHandle)
|
||||||
|
|
||||||
proc suspend(p: PProcess) =
|
proc suspend(p: PProcess) =
|
||||||
if kill(-p.id, SIGSTOP) != 0'i32: OSError(OSLastError())
|
if kill(-p.id, SIGSTOP) != 0'i32: osError(osLastError())
|
||||||
|
|
||||||
proc resume(p: PProcess) =
|
proc resume(p: PProcess) =
|
||||||
if kill(-p.id, SIGCONT) != 0'i32: OSError(OSLastError())
|
if kill(-p.id, SIGCONT) != 0'i32: osError(osLastError())
|
||||||
|
|
||||||
proc running(p: PProcess): bool =
|
proc running(p: PProcess): bool =
|
||||||
var ret = waitPid(p.id, p.exitCode, WNOHANG)
|
var ret = waitPid(p.id, p.exitCode, WNOHANG)
|
||||||
|
|
@ -742,8 +742,8 @@ elif not defined(useNimRtl):
|
||||||
proc terminate(p: PProcess) =
|
proc terminate(p: PProcess) =
|
||||||
if kill(-p.id, SIGTERM) == 0'i32:
|
if kill(-p.id, SIGTERM) == 0'i32:
|
||||||
if p.running():
|
if p.running():
|
||||||
if kill(-p.id, SIGKILL) != 0'i32: OSError(OSLastError())
|
if kill(-p.id, SIGKILL) != 0'i32: osError(osLastError())
|
||||||
else: OSError(OSLastError())
|
else: osError(osLastError())
|
||||||
|
|
||||||
proc waitForExit(p: PProcess, timeout: int = -1): int =
|
proc waitForExit(p: PProcess, timeout: int = -1): int =
|
||||||
#if waitPid(p.id, p.exitCode, 0) == int(p.id):
|
#if waitPid(p.id, p.exitCode, 0) == int(p.id):
|
||||||
|
|
@ -753,7 +753,7 @@ elif not defined(useNimRtl):
|
||||||
if p.exitCode != -3: return p.exitCode
|
if p.exitCode != -3: return p.exitCode
|
||||||
if waitPid(p.id, p.exitCode, 0) < 0:
|
if waitPid(p.id, p.exitCode, 0) < 0:
|
||||||
p.exitCode = -3
|
p.exitCode = -3
|
||||||
OSError(OSLastError())
|
osError(osLastError())
|
||||||
result = int(p.exitCode) shr 8
|
result = int(p.exitCode) shr 8
|
||||||
|
|
||||||
proc peekExitCode(p: PProcess): int =
|
proc peekExitCode(p: PProcess): int =
|
||||||
|
|
@ -767,7 +767,7 @@ elif not defined(useNimRtl):
|
||||||
proc createStream(stream: var PStream, handle: var TFileHandle,
|
proc createStream(stream: var PStream, handle: var TFileHandle,
|
||||||
fileMode: TFileMode) =
|
fileMode: TFileMode) =
|
||||||
var f: TFile
|
var f: TFile
|
||||||
if not open(f, handle, fileMode): OSError(OSLastError())
|
if not open(f, handle, fileMode): osError(osLastError())
|
||||||
stream = newFileStream(f)
|
stream = newFileStream(f)
|
||||||
|
|
||||||
proc inputStream(p: PProcess): PStream =
|
proc inputStream(p: PProcess): PStream =
|
||||||
|
|
|
||||||
|
|
@ -340,7 +340,7 @@ const
|
||||||
WSAEWOULDBLOCK* = 10035
|
WSAEWOULDBLOCK* = 10035
|
||||||
WSAEINPROGRESS* = 10036
|
WSAEINPROGRESS* = 10036
|
||||||
|
|
||||||
proc WSAGetLastError*(): cint {.importc: "WSAGetLastError", dynlib: ws2dll.}
|
proc wsaGetLastError*(): cint {.importc: "WSAGetLastError", dynlib: ws2dll.}
|
||||||
|
|
||||||
type
|
type
|
||||||
TSocketHandle* = distinct int
|
TSocketHandle* = distinct int
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue