diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index 20964b166a..5b0278d745 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -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: "".} + +when not defined(NimScript): + var + errno {.importc, header: "".}: 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 =