summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-08-22 13:15:19 +0200
committerAraq <rumpf_a@web.de>2018-08-22 13:15:19 +0200
commit7896903fd09ee5c855112660179b6f4ec57a1977 (patch)
tree9def8fcc5182b2ce1160a81e3adc98fcedbc502c /lib
parent64517445ea2347f29d91de44fe46ff78a6f655ab (diff)
downloadNim-7896903fd09ee5c855112660179b6f4ec57a1977.tar.gz
make tio test green again
Diffstat (limited to 'lib')
-rw-r--r--lib/system/sysio.nim10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim
index 75e26a6c9..40bbf97dc 100644
--- a/lib/system/sysio.nim
+++ b/lib/system/sysio.nim
@@ -143,13 +143,17 @@ proc getFileHandle*(f: File): FileHandle = c_fileno(f)
 
 proc readLine(f: File, line: var TaintedString): bool =
   var pos = 0
-  var sp: cint = 80
-  line.string.setLen(sp)
+
+  # Use the currently reserved space for a first try
+  var sp = line.string.len
+  if sp == 0:
+    sp = 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
     nimSetMem(addr line.string[pos], '\L'.ord, sp)
-    var fgetsSuccess = c_fgets(addr line.string[pos], sp, f) != nil
+    var fgetsSuccess = c_fgets(addr line.string[pos], sp.cint, f) != nil
     if not fgetsSuccess: checkErr(f)
     let m = c_memchr(addr line.string[pos], '\L'.ord, sp)
     if m != nil: