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
parent cc4720fac1
commit eba8ffcf70

View File

@@ -74,10 +74,21 @@ proc raiseEIO(msg: string) {.noinline, noreturn.} =
proc raiseEOF() {.noinline, noreturn.} =
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) =
if c_ferror(f) != 0:
c_clearerr(f)
raiseEIO("Unknown IO Error")
when not defined(NimScript):
if c_ferror(f) != 0:
let msg = "errno: " & $errno & " `" & $strerror(errno) & "`"
c_clearerr(f)
raiseEIO(msg)
else:
# shouldn't happen
quit(1)
{.push stackTrace:off, profiler:off.}
proc readBuffer(f: File, buffer: pointer, len: Natural): int =