diff options
author | Araq <rumpf_a@web.de> | 2017-02-09 20:11:54 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2017-02-09 20:11:54 +0100 |
commit | a20b4c674e9ee27d0ebb1da0163d7d3664808897 (patch) | |
tree | cd4a75a8c82042df7374c6493f7797e15c6383b3 | |
parent | 5ff6ff28bf9abf12fa9d82f0323954516a855b6a (diff) | |
download | Nim-a20b4c674e9ee27d0ebb1da0163d7d3664808897.tar.gz |
sysio: minor improvements
-rw-r--r-- | lib/system/sysio.nim | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index 9f4944eb0..115b67c18 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 |