From a20b4c674e9ee27d0ebb1da0163d7d3664808897 Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 9 Feb 2017 20:11:54 +0100 Subject: [PATCH] sysio: minor improvements --- lib/system/sysio.nim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index 9f4944eb0f..115b67c18f 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -67,7 +67,7 @@ proc checkErr(f: File) = {.push stackTrace:off, profiler:off.} proc readBuffer(f: File, buffer: pointer, len: Natural): int = result = c_fread(buffer, 1, len, f) - checkErr(f) + if result != len: checkErr(f) proc readBytes(f: File, a: var openArray[int8|uint8], start, len: Natural): int = result = readBuffer(f, addr(a[start]), len) @@ -118,8 +118,9 @@ const proc close*(f: File) = discard c_fclose(f) proc readChar(f: File): char = let x = c_fgetc(f) - if x == -1: raiseEOF() - checkErr(f) + if x < 0: + checkErr(f) + raiseEOF() result = char(x) proc flushFile*(f: File) = discard c_fflush(f) @@ -140,7 +141,7 @@ proc readLine(f: File, line: var TaintedString): bool = # fgets doesn't append an \L c_memset(addr line.string[pos], '\L'.ord, sp) var fgetsSuccess = c_fgets(addr line.string[pos], sp, f) != nil - checkErr(f) + if not fgetsSuccess: checkErr(f) let m = c_memchr(addr line.string[pos], '\L'.ord, sp) if m != nil: # \l found: Could be our own or the one by fgets, in any case, we're done