From 518fa2e29a6a83541d3a6875e26e276d71704a03 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Thu, 25 Nov 2010 00:59:40 +0100 Subject: [PATCH] node_stdio stub for windows --- src/node_stdio.cc | 8 +++++ src/node_stdio_win32.cc | 68 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/node_stdio_win32.cc diff --git a/src/node_stdio.cc b/src/node_stdio.cc index ad098352b9..c2f5cbb4ca 100644 --- a/src/node_stdio.cc +++ b/src/node_stdio.cc @@ -1,3 +1,9 @@ +#ifdef __MINGW32__ +# include "node_stdio_win32.cc" +#endif + +#ifdef __POSIX__ + #include #include @@ -292,3 +298,5 @@ void Stdio::Initialize(v8::Handle target) { } // namespace node NODE_MODULE(node_stdio, node::Stdio::Initialize); + +#endif // __POSIX__ diff --git a/src/node_stdio_win32.cc b/src/node_stdio_win32.cc new file mode 100644 index 0000000000..c609fddd2d --- /dev/null +++ b/src/node_stdio_win32.cc @@ -0,0 +1,68 @@ +#include +#include +#include + +using namespace v8; +namespace node { + + +NO_IMPL(void, Stdio::DisableRawMode, , int fd); +NO_IMPL(void, Stdio::Flush, , ); +NO_IMPL(static Handle, OpenStdin, RET_V8UNDEFINED, const Arguments& args); +NO_IMPL(static Handle, IsStdinBlocking, RET_V8FALSE, const Arguments& args); +NO_IMPL(static Handle, SetRawMode, RET_V8TRUE, const Arguments& args); +NO_IMPL(static Handle, GetColumns, RET_V8INT(80), const Arguments& args); +NO_IMPL(static Handle, GetRows, RET_V8INT(25), const Arguments& args); +NO_IMPL(static Handle, IsATTY, RET_V8FALSE, const Arguments& args); + + +/* + * STDERR should always be blocking & utf-8 + * TODO: check correctness + */ +static Handle +WriteError (const Arguments& args) +{ + HandleScope scope; + + if (args.Length() < 1) + return Undefined(); + + String::Utf8Value msg(args[0]->ToString()); + + fprintf(stderr, "%s", (char*)*msg); + + return Undefined(); +} + + +/* + * Assume that stdout is never blocking on windows + * TODO: check correctness and really implement this + */ +static Handle +IsStdoutBlocking (const Arguments& args) +{ + return True(); +} + + +void Stdio::Initialize(v8::Handle target) { + target->Set(String::NewSymbol("stdoutFD"), Integer::New(STDOUT_FILENO)); + target->Set(String::NewSymbol("stderrFD"), Integer::New(STDERR_FILENO)); + target->Set(String::NewSymbol("stdinFD"), Integer::New(STDIN_FILENO)); + + NODE_SET_METHOD(target, "writeError", WriteError); + NODE_SET_METHOD(target, "openStdin", OpenStdin); + NODE_SET_METHOD(target, "isStdoutBlocking", IsStdoutBlocking); + NODE_SET_METHOD(target, "isStdinBlocking", IsStdinBlocking); + NODE_SET_METHOD(target, "setRawMode", SetRawMode); + NODE_SET_METHOD(target, "getColumns", GetColumns); + NODE_SET_METHOD(target, "getRows", GetRows); + NODE_SET_METHOD(target, "isatty", IsATTY); +} + + +} // namespace node + +NODE_MODULE(node_stdio, node::Stdio::Initialize);