summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2017-10-16 16:46:38 +0200
committerAndreas Rumpf <rumpf_a@web.de>2017-10-16 16:47:10 +0200
commit7eeef4aae7391f0e9e53c9009cf722545cee954c (patch)
treef19e38274485b785b39f3c80eba62895bf2c0f8a /lib
parent309838c6edc67b17e6366a0681db2875997ccd0d (diff)
downloadNim-7eeef4aae7391f0e9e53c9009cf722545cee954c.tar.gz
fixes #1137
Diffstat (limited to 'lib')
-rw-r--r--lib/system/sysio.nim12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim
index 4f266e0ae..c0da983f1 100644
--- a/lib/system/sysio.nim
+++ b/lib/system/sysio.nim
@@ -404,4 +404,16 @@ proc setStdIoUnbuffered() =
   when declared(stdin):
     discard c_setvbuf(stdin, nil, IONBF, 0)
 
+when declared(stdout):
+  proc echoBinSafe(args: openArray[string]) {.compilerProc.} =
+    proc flockfile(f: File) {.importc, noDecl.}
+    proc funlockfile(f: File) {.importc, noDecl.}
+    flockfile(stdout)
+    for s in args:
+      discard c_fwrite(s.cstring, s.len, 1, stdout)
+    const linefeed = "\n" # can be 1 or more chars
+    discard c_fwrite(linefeed.cstring, linefeed.len, 1, stdout)
+    discard c_fflush(stdout)
+    funlockfile(stdout)
+
 {.pop.}