diff --git a/lib/system/ansi_c.nim b/lib/system/ansi_c.nim index b9f719d9e604d..55e004f6e40ab 100644 --- a/lib/system/ansi_c.nim +++ b/lib/system/ansi_c.nim @@ -116,9 +116,15 @@ type incompleteStruct.} = object CFilePtr* = ptr CFile ## The type representing a file handle. +# duplicated between io and ansi_c +const stderrName = when defined(osx): "__stderrp" else: "stderr" +const stdoutName = when defined(osx): "__stdoutp" else: "stdout" +const stdinName = when defined(osx): "__stdinp" else: "stdin" + var - cstderr* {.importc: "stderr", header: "".}: CFilePtr - cstdout* {.importc: "stdout", header: "".}: CFilePtr + cstderr* {.importc: stderrName, header: "".}: CFilePtr + cstdout* {.importc: stdoutName, header: "".}: CFilePtr + cstdin* {.importc: stdinName, header: "".}: CFilePtr proc c_fprintf*(f: CFilePtr, frmt: cstring): cint {. importc: "fprintf", header: "", varargs, discardable.} diff --git a/lib/system/io.nim b/lib/system/io.nim index 62722140fd78b..a8f690054f73c 100644 --- a/lib/system/io.nim +++ b/lib/system/io.nim @@ -35,12 +35,17 @@ type # text file handling: when not defined(nimscript) and not defined(js): + # duplicated between io and ansi_c + const stderrName = when defined(osx): "__stderrp" else: "stderr" + const stdoutName = when defined(osx): "__stdoutp" else: "stdout" + const stdinName = when defined(osx): "__stdinp" else: "stdin" + var - stdin* {.importc: "stdin", header: "".}: File + stdin* {.importc: stdinName, header: "".}: File ## The standard input stream. - stdout* {.importc: "stdout", header: "".}: File + stdout* {.importc: stdoutName, header: "".}: File ## The standard output stream. - stderr* {.importc: "stderr", header: "".}: File + stderr* {.importc: stderrName, header: "".}: File ## The standard error stream. when defined(useStdoutAsStdmsg): diff --git a/tests/vm/tevalffi.nim b/tests/vm/tevalffi.nim index 963d2a58e4612..c2abdba5d0f1a 100644 --- a/tests/vm/tevalffi.nim +++ b/tests/vm/tevalffi.nim @@ -8,6 +8,8 @@ foo:102:103 foo:102:103:104 foo:0.03:asdf:103:105 ret={s1:foobar s2:foobar age:25 pi:3.14} +hello world stderr +hi stderr ''' output: ''' foo @@ -17,6 +19,8 @@ foo:102:103 foo:102:103:104 foo:0.03:asdf:103:105 ret={s1:foobar s2:foobar age:25 pi:3.14} +hello world stderr +hi stderr ''' disabled: "true" """ @@ -76,6 +80,15 @@ proc fun() = if false: c_printf("foo2:a=%d\n", a2) + static: fun() fun() + +when true: + import system/ansi_c + proc fun2()= + c_fprintf(cstderr, "hello world stderr\n") + write(stderr, "hi stderr\n") + static: fun2() + fun2()