checkErr now shows actual system error msg instead of unknown error (#9987)

This commit is contained in:
Timothee Cour 2018-12-27 13:46:53 -08:00 • committed by Andreas Rumpf
commit eba8ffcf70

View file

@ -74,10 +74,21 @@ proc raiseEIO(msg: string) {.noinline, noreturn.} =
proc raiseEOF() {.noinline, noreturn.} = proc raiseEOF() {.noinline, noreturn.} =
sysFatal(EOFError, "EOF reached") sysFatal(EOFError, "EOF reached")
proc strerror(errnum: cint): cstring {.importc, header: "<string.h>".}
when not defined(NimScript):
var
errno {.importc, header: "<errno.h>".}: cint ## error variable
proc checkErr(f: File) = proc checkErr(f: File) =
if c_ferror(f) != 0: when not defined(NimScript):
c_clearerr(f) if c_ferror(f) != 0:
raiseEIO("Unknown IO Error") let msg = "errno: " & $errno & " `" & $strerror(errno) & "`"
c_clearerr(f)
raiseEIO(msg)
else:
# shouldn't happen
quit(1)
{.push stackTrace:off, profiler:off.} {.push stackTrace:off, profiler:off.}
proc readBuffer(f: File, buffer: pointer, len: Natural): int = proc readBuffer(f: File, buffer: pointer, len: Natural): int =