diff --git a/lib/system/io.nim b/lib/system/io.nim index e93f602ae2d44..71b719e3ab523 100644 --- a/lib/system/io.nim +++ b/lib/system/io.nim @@ -126,6 +126,7 @@ proc strerror(errnum: cint): cstring {.importc, header: "".} when not defined(NimScript): var errno {.importc, header: "".}: cint ## error variable + EINTR {.importc: "EINTR", header: "".}: cint proc checkErr(f: File) = when not defined(NimScript): @@ -137,14 +138,24 @@ proc checkErr(f: File) = # shouldn't happen quit(1) + + {.push stackTrace:off, profiler:off.} proc readBuffer*(f: File, buffer: pointer, len: Natural): int {. tags: [ReadIOEffect], benign.} = ## reads `len` bytes into the buffer pointed to by `buffer`. Returns ## the actual number of bytes that have been read which may be less than ## `len` (if not as many bytes are remaining), but not greater. - result = c_fread(buffer, 1, len, f) - if result != len: checkErr(f) + while true: + result = c_fread(buffer, 1, len, f) + if result == len: return result + when not defined(NimScript): + if errno == EINTR: + errno = 0 + c_clearerr(f) + continue + checkErr(f) + break proc readBytes*(f: File, a: var openArray[int8|uint8], start, len: Natural): int {. tags: [ReadIOEffect], benign.} =