diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2017-11-02 10:46:30 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-11-02 10:46:30 +0100 |
commit | 1eaeccc15d15d15d2f62ea1648f7dd64722dbd37 (patch) | |
tree | b922cdabc780fa3a8837a6804d2df31793d9e2ca /lib/system/sysio.nim | |
parent | e9243a16167b24899d4fcf051f3252b3a5804811 (diff) | |
parent | bd19b5f4d36bb40b4af93d7e15fdfa582e9fe3b7 (diff) | |
download | Nim-1eaeccc15d15d15d2f62ea1648f7dd64722dbd37.tar.gz |
Merge branch 'devel' into araq
Diffstat (limited to 'lib/system/sysio.nim')
-rw-r--r-- | lib/system/sysio.nim | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index 7b6d93fe0..a40fcc67d 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -15,9 +15,12 @@ {.push debugger:off .} # the user does not want to trace a part # of the standard library! - -proc c_fdopen(filehandle: cint, mode: cstring): File {. - importc: "fdopen", header: "<stdio.h>".} +when defined(windows): + proc c_fdopen(filehandle: cint, mode: cstring): File {. + importc: "_fdopen", header: "<stdio.h>".} +else: + proc c_fdopen(filehandle: cint, mode: cstring): File {. + importc: "fdopen", header: "<stdio.h>".} proc c_fputs(c: cstring, f: File): cint {. importc: "fputs", header: "<stdio.h>", tags: [WriteIOEffect].} proc c_fgets(c: cstring, n: cint, f: File): cstring {. @@ -401,4 +404,18 @@ proc setStdIoUnbuffered() = when declared(stdin): discard c_setvbuf(stdin, nil, IONBF, 0) +when declared(stdout): + proc echoBinSafe(args: openArray[string]) {.compilerProc.} = + when not defined(windows): + 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) + when not defined(windows): + funlockfile(stdout) + {.pop.} |