File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55#include < unistd.h>
66#include < fcntl.h>
7+ #include < string.h>
8+ #include < errno.h>
79
810using namespace v8 ;
911using namespace node ;
@@ -42,6 +44,15 @@ EmitClose (void)
4244 emit->Call (stdio, 1 , argv);
4345}
4446
47+
48+ static inline Local<Value> errno_exception (int errorno) {
49+ Local<Value> e = Exception::Error (String::NewSymbol (strerror (errorno)));
50+ Local<Object> obj = e->ToObject ();
51+ obj->Set (String::NewSymbol (" errno" ), Integer::New (errorno));
52+ return e;
53+ }
54+
55+
4556/* STDERR IS ALWAY SYNC */
4657static Handle<Value>
4758WriteError (const Arguments& args)
@@ -53,8 +64,13 @@ WriteError (const Arguments& args)
5364
5465 String::Utf8Value msg (args[0 ]->ToString ());
5566
56- fprintf (stderr, " %s" , *msg);
57- fflush (stderr);
67+ ssize_t r;
68+ size_t written = 0 ;
69+ while (written < msg.length ()) {
70+ r = write (STDERR_FILENO , (*msg) + written, msg.length () - written);
71+ if (r < 0 ) return ThrowException (errno_exception (errno));
72+ written += (size_t )r;
73+ }
5874
5975 return Undefined ();
6076}
You can’t perform that action at this time.
0 commit comments