summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-10-08 20:49:45 +0200
committerGitHub <noreply@github.com>2019-10-08 20:49:45 +0200
commitf30da2f26628d58274363b527e7099bdd44f707d (patch)
treefaf55a7bfe1e9b59af18cc54a83649fee1359d86 /lib/system
parent00c31e87660d9db813871f5aa23661bf6b9bbdcb (diff)
downloadNim-f30da2f26628d58274363b527e7099bdd44f707d.tar.gz
fixes #12315 [backport]; refs #12314 (#12385)
Diffstat (limited to 'lib/system')
-rw-r--r--lib/system/io.nim6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/system/io.nim b/lib/system/io.nim
index 46863064b..888ff8e7f 100644
--- a/lib/system/io.nim
+++ b/lib/system/io.nim
@@ -118,6 +118,8 @@ proc c_setvbuf(f: File, buf: pointer, mode: cint, size: int): cint {.
 
 proc c_fprintf(f: File, frmt: cstring): cint {.
   importc: "fprintf", header: "<stdio.h>", varargs, discardable.}
+proc c_fputc(c: char, f: File): cint {.
+  importc: "fputc", header: "<stdio.h>".}
 
 ## When running nim in android app stdout goes no where, so echo gets ignored
 ## To redreict echo to the android logcat use -d:androidNDK
@@ -218,6 +220,10 @@ when defined(windows):
     var i = c_fprintf(f, "%s", s)
     while i < s.len:
       if s[i] == '\0':
+        let w = c_fputc('\0', f)
+        if w != 0:
+          if doRaise: raiseEIO("cannot write string to file")
+          break
         inc i
       else:
         let w = c_fprintf(f, "%s", unsafeAddr s[i])