Fixed OSError deprecation warnings.
This commit is contained in:
parent
5d3b5eb700
commit
9686d92bfc
3 changed files with 35 additions and 32 deletions
|
|
@ -264,7 +264,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()
|
if a == 0 and br != 0: OSError(OSLastError())
|
||||||
s.atTheEnd = br < bufLen
|
s.atTheEnd = br < bufLen
|
||||||
result = br
|
result = br
|
||||||
|
|
||||||
|
|
@ -272,7 +272,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()
|
if a == 0: OSError(OSLastError())
|
||||||
|
|
||||||
proc newFileHandleStream(handle: THandle): PFileHandleStream =
|
proc newFileHandleStream(handle: THandle): PFileHandleStream =
|
||||||
new(result)
|
new(result)
|
||||||
|
|
@ -313,7 +313,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()
|
OSError(OSLastError())
|
||||||
|
|
||||||
proc fileClose(h: THandle) {.inline.} =
|
proc fileClose(h: THandle) {.inline.} =
|
||||||
if h > 4: discard CloseHandle(h)
|
if h > 4: discard CloseHandle(h)
|
||||||
|
|
@ -474,7 +474,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()
|
OSError(OSLastError())
|
||||||
else:
|
else:
|
||||||
var i = ret - WAIT_OBJECT_0
|
var i = ret - WAIT_OBJECT_0
|
||||||
readfds.del(i)
|
readfds.del(i)
|
||||||
|
|
@ -532,7 +532,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()
|
OSError(OSLastError())
|
||||||
|
|
||||||
var pid: TPid
|
var pid: TPid
|
||||||
when defined(posix_spawn) and not defined(useFork):
|
when defined(posix_spawn) and not defined(useFork):
|
||||||
|
|
@ -540,7 +540,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()
|
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)
|
||||||
|
|
@ -585,20 +585,20 @@ elif not defined(useNimRtl):
|
||||||
else:
|
else:
|
||||||
|
|
||||||
Pid = fork()
|
Pid = fork()
|
||||||
if Pid < 0: OSError()
|
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()
|
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()
|
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()
|
if dup2(p_stdout[writeIdx], 2) < 0: OSError(OSLastError())
|
||||||
else:
|
else:
|
||||||
if dup2(p_stderr[writeIdx], 2) < 0: OSError()
|
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))
|
||||||
|
|
@ -653,10 +653,10 @@ elif not defined(useNimRtl):
|
||||||
discard close(p.errorHandle)
|
discard close(p.errorHandle)
|
||||||
|
|
||||||
proc suspend(p: PProcess) =
|
proc suspend(p: PProcess) =
|
||||||
if kill(-p.id, SIGSTOP) != 0'i32: OSError()
|
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()
|
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)
|
||||||
|
|
@ -666,8 +666,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()
|
if kill(-p.id, SIGKILL) != 0'i32: OSError(OSLastError())
|
||||||
else: OSError()
|
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):
|
||||||
|
|
@ -677,7 +677,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()
|
OSError(OSLastError())
|
||||||
result = int(p.exitCode) shr 8
|
result = int(p.exitCode) shr 8
|
||||||
|
|
||||||
proc peekExitCode(p: PProcess): int =
|
proc peekExitCode(p: PProcess): int =
|
||||||
|
|
@ -691,7 +691,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()
|
if not open(f, handle, fileMode): OSError(OSLastError())
|
||||||
stream = newFileStream(f)
|
stream = newFileStream(f)
|
||||||
|
|
||||||
proc inputStream(p: PProcess): PStream =
|
proc inputStream(p: PProcess): PStream =
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,11 @@ when defined(windows):
|
||||||
var hTemp = GetStdHandle(STD_OUTPUT_HANDLE)
|
var hTemp = GetStdHandle(STD_OUTPUT_HANDLE)
|
||||||
if DuplicateHandle(GetCurrentProcess(), hTemp, GetCurrentProcess(),
|
if DuplicateHandle(GetCurrentProcess(), hTemp, GetCurrentProcess(),
|
||||||
addr(conHandle), 0, 1, DUPLICATE_SAME_ACCESS) == 0:
|
addr(conHandle), 0, 1, DUPLICATE_SAME_ACCESS) == 0:
|
||||||
OSError()
|
OSError(OSLastError())
|
||||||
|
|
||||||
proc getCursorPos(): tuple [x,y: int] =
|
proc getCursorPos(): tuple [x,y: int] =
|
||||||
var c: TCONSOLE_SCREEN_BUFFER_INFO
|
var c: TCONSOLE_SCREEN_BUFFER_INFO
|
||||||
if GetConsoleScreenBufferInfo(conHandle, addr(c)) == 0: OSError()
|
if GetConsoleScreenBufferInfo(conHandle, addr(c)) == 0: OSError(OSLastError())
|
||||||
return (int(c.dwCursorPosition.x), int(c.dwCursorPosition.y))
|
return (int(c.dwCursorPosition.x), int(c.dwCursorPosition.y))
|
||||||
|
|
||||||
proc getAttributes(): int16 =
|
proc getAttributes(): int16 =
|
||||||
|
|
@ -51,7 +51,7 @@ proc setCursorPos*(x, y: int) =
|
||||||
var c: TCoord
|
var c: TCoord
|
||||||
c.x = int16(x)
|
c.x = int16(x)
|
||||||
c.y = int16(y)
|
c.y = int16(y)
|
||||||
if SetConsoleCursorPosition(conHandle, c) == 0: OSError()
|
if SetConsoleCursorPosition(conHandle, c) == 0: OSError(OSLastError())
|
||||||
else:
|
else:
|
||||||
stdout.write("\e[" & $y & ';' & $x & 'f')
|
stdout.write("\e[" & $y & ';' & $x & 'f')
|
||||||
|
|
||||||
|
|
@ -61,10 +61,10 @@ proc setCursorXPos*(x: int) =
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
var scrbuf: TCONSOLE_SCREEN_BUFFER_INFO
|
var scrbuf: TCONSOLE_SCREEN_BUFFER_INFO
|
||||||
var hStdout = conHandle
|
var hStdout = conHandle
|
||||||
if GetConsoleScreenBufferInfo(hStdout, addr(scrbuf)) == 0: OSError()
|
if GetConsoleScreenBufferInfo(hStdout, addr(scrbuf)) == 0: OSError(OSLastError())
|
||||||
var origin = scrbuf.dwCursorPosition
|
var origin = scrbuf.dwCursorPosition
|
||||||
origin.x = int16(x)
|
origin.x = int16(x)
|
||||||
if SetConsoleCursorPosition(conHandle, origin) == 0: OSError()
|
if SetConsoleCursorPosition(conHandle, origin) == 0: OSError(OSLastError())
|
||||||
else:
|
else:
|
||||||
stdout.write("\e[" & $x & 'G')
|
stdout.write("\e[" & $x & 'G')
|
||||||
|
|
||||||
|
|
@ -75,10 +75,10 @@ when defined(windows):
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
var scrbuf: TCONSOLE_SCREEN_BUFFER_INFO
|
var scrbuf: TCONSOLE_SCREEN_BUFFER_INFO
|
||||||
var hStdout = conHandle
|
var hStdout = conHandle
|
||||||
if GetConsoleScreenBufferInfo(hStdout, addr(scrbuf)) == 0: OSError()
|
if GetConsoleScreenBufferInfo(hStdout, addr(scrbuf)) == 0: OSError(OSLastError())
|
||||||
var origin = scrbuf.dwCursorPosition
|
var origin = scrbuf.dwCursorPosition
|
||||||
origin.y = int16(y)
|
origin.y = int16(y)
|
||||||
if SetConsoleCursorPosition(conHandle, origin) == 0: OSError()
|
if SetConsoleCursorPosition(conHandle, origin) == 0: OSError(OSLastError())
|
||||||
else:
|
else:
|
||||||
nil
|
nil
|
||||||
|
|
||||||
|
|
@ -155,18 +155,18 @@ proc EraseLine* =
|
||||||
var scrbuf: TCONSOLE_SCREEN_BUFFER_INFO
|
var scrbuf: TCONSOLE_SCREEN_BUFFER_INFO
|
||||||
var numwrote: DWORD
|
var numwrote: DWORD
|
||||||
var hStdout = conHandle
|
var hStdout = conHandle
|
||||||
if GetConsoleScreenBufferInfo(hStdout, addr(scrbuf)) == 0: OSError()
|
if GetConsoleScreenBufferInfo(hStdout, addr(scrbuf)) == 0: OSError(OSLastError())
|
||||||
var origin = scrbuf.dwCursorPosition
|
var origin = scrbuf.dwCursorPosition
|
||||||
origin.x = 0'i16
|
origin.x = 0'i16
|
||||||
if SetConsoleCursorPosition(conHandle, origin) == 0: OSError()
|
if SetConsoleCursorPosition(conHandle, origin) == 0: OSError(OSLastError())
|
||||||
var ht = scrbuf.dwSize.Y - origin.Y
|
var ht = scrbuf.dwSize.Y - origin.Y
|
||||||
var wt = scrbuf.dwSize.X - origin.X
|
var wt = scrbuf.dwSize.X - origin.X
|
||||||
if FillConsoleOutputCharacter(hStdout,' ', ht*wt,
|
if FillConsoleOutputCharacter(hStdout,' ', ht*wt,
|
||||||
origin, addr(numwrote)) == 0:
|
origin, addr(numwrote)) == 0:
|
||||||
OSError()
|
OSError(OSLastError())
|
||||||
if FillConsoleOutputAttribute(hStdout, scrbuf.wAttributes, ht * wt,
|
if FillConsoleOutputAttribute(hStdout, scrbuf.wAttributes, ht * wt,
|
||||||
scrbuf.dwCursorPosition, addr(numwrote)) == 0:
|
scrbuf.dwCursorPosition, addr(numwrote)) == 0:
|
||||||
OSError()
|
OSError(OSLastError())
|
||||||
else:
|
else:
|
||||||
stdout.write("\e[2K")
|
stdout.write("\e[2K")
|
||||||
setCursorXPos(0)
|
setCursorXPos(0)
|
||||||
|
|
@ -178,14 +178,14 @@ proc EraseScreen* =
|
||||||
var numwrote: DWORD
|
var numwrote: DWORD
|
||||||
var origin: TCoord # is inititalized to 0, 0
|
var origin: TCoord # is inititalized to 0, 0
|
||||||
var hStdout = conHandle
|
var hStdout = conHandle
|
||||||
if GetConsoleScreenBufferInfo(hStdout, addr(scrbuf)) == 0: OSError()
|
if GetConsoleScreenBufferInfo(hStdout, addr(scrbuf)) == 0: OSError(OSLastError())
|
||||||
if FillConsoleOutputCharacter(hStdout, ' ', scrbuf.dwSize.X*scrbuf.dwSize.Y,
|
if FillConsoleOutputCharacter(hStdout, ' ', scrbuf.dwSize.X*scrbuf.dwSize.Y,
|
||||||
origin, addr(numwrote)) == 0:
|
origin, addr(numwrote)) == 0:
|
||||||
OSError()
|
OSError(OSLastError())
|
||||||
if FillConsoleOutputAttribute(hStdout, scrbuf.wAttributes,
|
if FillConsoleOutputAttribute(hStdout, scrbuf.wAttributes,
|
||||||
scrbuf.dwSize.X * scrbuf.dwSize.Y,
|
scrbuf.dwSize.X * scrbuf.dwSize.Y,
|
||||||
origin, addr(numwrote)) == 0:
|
origin, addr(numwrote)) == 0:
|
||||||
OSError()
|
OSError(OSLastError())
|
||||||
setCursorXPos(0)
|
setCursorXPos(0)
|
||||||
else:
|
else:
|
||||||
stdout.write("\e[2J")
|
stdout.write("\e[2J")
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,10 @@ Changes affecting backwards compatibility
|
||||||
|
|
||||||
- The scoping rules for the ``if`` statement changed for better interaction
|
- The scoping rules for the ``if`` statement changed for better interaction
|
||||||
with the new syntactic construct ``(;)``.
|
with the new syntactic construct ``(;)``.
|
||||||
|
- ``OSError`` family of procedures has been deprecated. Procedures with the same
|
||||||
|
name but which take different parameters have been introduced. These procs now
|
||||||
|
require an error code to be passed to them. This error code can be retrieved
|
||||||
|
using the new ``OSLastError`` proc.
|
||||||
|
|
||||||
|
|
||||||
Compiler Additions
|
Compiler Additions
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue