diff --git a/lib/system/ansi_c.nim b/lib/system/ansi_c.nim index 0b4b259921222..0cab0914db78c 100644 --- a/lib/system/ansi_c.nim +++ b/lib/system/ansi_c.nim @@ -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: "".}: CFilePtr - cstdout* {.importc: stdoutName, header: "".}: CFilePtr cstdin* {.importc: stdinName, header: "".}: CFilePtr + cstdout* {.importc: stdoutName, header: "".}: CFilePtr + cstderr* {.importc: stderrName, header: "".}: CFilePtr proc c_fprintf*(f: CFilePtr, frmt: cstring): cint {. importc: "fprintf", header: "", varargs, discardable.}