diff options
Diffstat (limited to 'lib/system/sysio.nim')
-rw-r--r-- | lib/system/sysio.nim | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index 40bbf97dc..61835e0f7 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -145,10 +145,9 @@ proc readLine(f: File, line: var TaintedString): bool = var pos = 0 # Use the currently reserved space for a first try - var sp = line.string.len - if sp == 0: - sp = 80 - line.string.setLen(sp) + var sp = max(line.string.len, 80) + line.string.setLen(sp) + while true: # memset to \L so that we can tell how far fgets wrote, even on EOF, where # fgets doesn't append an \L @@ -161,7 +160,7 @@ proc readLine(f: File, line: var TaintedString): bool = var last = cast[ByteAddress](m) - cast[ByteAddress](addr line.string[0]) if last > 0 and line.string[last-1] == '\c': line.string.setLen(last-1) - return fgetsSuccess + return last > 1 or fgetsSuccess # We have to distinguish between two possible cases: # \0\l\0 => line ending in a null character. # \0\l\l => last line without newline, null was put there by fgets. @@ -169,7 +168,7 @@ proc readLine(f: File, line: var TaintedString): bool = if last < pos + sp - 1 and line.string[last+1] != '\0': dec last line.string.setLen(last) - return fgetsSuccess + return last > 0 or fgetsSuccess else: # fgets will have inserted a null byte at the end of the string. dec sp |