Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed May 6, 2020
1 parent eca114e commit c1f7ab5
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/system/ansi_c.nim
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,25 @@ type
CFilePtr* = ptr CFile ## The type representing a file handle.

# duplicated between io and ansi_c
const stdioUsesMacros = (defined(osx) or defined(freebsd) or defined(dragonfly)) and not defined(emscripten)
const stderrName = when stdioUsesMacros: "__stderrp" else: "stderr"
const stdoutName = when stdioUsesMacros: "__stdoutp" else: "stdout"
const stdinName = when stdioUsesMacros: "__stdinp" else: "stdin"
# xxx super hacky, can be fixed by calling preprocessor
# see https://github.com/nim-lang/RFCs/issues/205 prop 5
when (defined(osx) or defined(freebsd) or defined(dragonfly)) and not defined(emscripten):
const stdinName = "__stdinp"
const stdoutName = "__stdoutp"
const stderrName = "__stderrp"
elif defined(openbsd) and not defined(emscripten):
const stdinName = "(&__sF[0])"
const stdoutName = "(&__sF[1])"
const stderrName = "(&__sF[2])"
else:
const stdinName = "stdin"
const stdoutName = "stdout"
const stderrName = "stderr"

var
cstderr* {.importc: stderrName, header: "<stdio.h>".}: CFilePtr
cstdout* {.importc: stdoutName, header: "<stdio.h>".}: CFilePtr
cstdin* {.importc: stdinName, header: "<stdio.h>".}: CFilePtr
cstdout* {.importc: stdoutName, header: "<stdio.h>".}: CFilePtr
cstderr* {.importc: stderrName, header: "<stdio.h>".}: CFilePtr

proc c_fprintf*(f: CFilePtr, frmt: cstring): cint {.
importc: "fprintf", header: "<stdio.h>", varargs, discardable.}
Expand Down

0 comments on commit c1f7ab5

Please sign in to comment.