Browse Source

Unify ErrnoException creation

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
c9e27b11c5
  1. 350
      src/node.cc
  2. 4
      src/node.h
  3. 6
      src/node_cares.cc
  4. 17
      src/node_crypto.cc
  5. 1
      src/node_events.cc
  6. 44
      src/node_file.cc
  7. 340
      src/node_net2.cc
  8. 10
      src/node_stdio.cc

350
src/node.cc

@ -50,6 +50,9 @@ namespace node {
static Persistent<Object> process;
static Persistent<String> errno_symbol;
static Persistent<String> syscall_symbol;
static Persistent<String> dev_symbol;
static Persistent<String> ino_symbol;
static Persistent<String> mode_symbol;
@ -278,6 +281,353 @@ static void EIODonePoll(void) {
}
static inline const char *errno_string(int errorno) {
#define ERRNO_CASE(e) case e: return #e;
switch (errorno) {
#ifdef EACCES
ERRNO_CASE(EACCES);
#endif
#ifdef EADDRINUSE
ERRNO_CASE(EADDRINUSE);
#endif
#ifdef EADDRNOTAVAIL
ERRNO_CASE(EADDRNOTAVAIL);
#endif
#ifdef EAFNOSUPPORT
ERRNO_CASE(EAFNOSUPPORT);
#endif
#ifdef EAGAIN
ERRNO_CASE(EAGAIN);
#else
# ifdef EWOULDBLOCK
ERRNO_CASE(EWOULDBLOCK);
# endif
#endif
#ifdef EALREADY
ERRNO_CASE(EALREADY);
#endif
#ifdef EBADF
ERRNO_CASE(EBADF);
#endif
#ifdef EBADMSG
ERRNO_CASE(EBADMSG);
#endif
#ifdef EBUSY
ERRNO_CASE(EBUSY);
#endif
#ifdef ECANCELED
ERRNO_CASE(ECANCELED);
#endif
#ifdef ECHILD
ERRNO_CASE(ECHILD);
#endif
#ifdef ECONNABORTED
ERRNO_CASE(ECONNABORTED);
#endif
#ifdef ECONNREFUSED
ERRNO_CASE(ECONNREFUSED);
#endif
#ifdef ECONNRESET
ERRNO_CASE(ECONNRESET);
#endif
#ifdef EDEADLK
ERRNO_CASE(EDEADLK);
#endif
#ifdef EDESTADDRREQ
ERRNO_CASE(EDESTADDRREQ);
#endif
#ifdef EDOM
ERRNO_CASE(EDOM);
#endif
#ifdef EDQUOT
ERRNO_CASE(EDQUOT);
#endif
#ifdef EEXIST
ERRNO_CASE(EEXIST);
#endif
#ifdef EFAULT
ERRNO_CASE(EFAULT);
#endif
#ifdef EFBIG
ERRNO_CASE(EFBIG);
#endif
#ifdef EHOSTUNREACH
ERRNO_CASE(EHOSTUNREACH);
#endif
#ifdef EIDRM
ERRNO_CASE(EIDRM);
#endif
#ifdef EILSEQ
ERRNO_CASE(EILSEQ);
#endif
#ifdef EINPROGRESS
ERRNO_CASE(EINPROGRESS);
#endif
#ifdef EINTR
ERRNO_CASE(EINTR);
#endif
#ifdef EINVAL
ERRNO_CASE(EINVAL);
#endif
#ifdef EIO
ERRNO_CASE(EIO);
#endif
#ifdef EISCONN
ERRNO_CASE(EISCONN);
#endif
#ifdef EISDIR
ERRNO_CASE(EISDIR);
#endif
#ifdef ELOOP
ERRNO_CASE(ELOOP);
#endif
#ifdef EMFILE
ERRNO_CASE(EMFILE);
#endif
#ifdef EMLINK
ERRNO_CASE(EMLINK);
#endif
#ifdef EMSGSIZE
ERRNO_CASE(EMSGSIZE);
#endif
#ifdef EMULTIHOP
ERRNO_CASE(EMULTIHOP);
#endif
#ifdef ENAMETOOLONG
ERRNO_CASE(ENAMETOOLONG);
#endif
#ifdef ENETDOWN
ERRNO_CASE(ENETDOWN);
#endif
#ifdef ENETRESET
ERRNO_CASE(ENETRESET);
#endif
#ifdef ENETUNREACH
ERRNO_CASE(ENETUNREACH);
#endif
#ifdef ENFILE
ERRNO_CASE(ENFILE);
#endif
#ifdef ENOBUFS
ERRNO_CASE(ENOBUFS);
#endif
#ifdef ENODATA
ERRNO_CASE(ENODATA);
#endif
#ifdef ENODEV
ERRNO_CASE(ENODEV);
#endif
#ifdef ENOENT
ERRNO_CASE(ENOENT);
#endif
#ifdef ENOEXEC
ERRNO_CASE(ENOEXEC);
#endif
#ifdef ENOLCK
ERRNO_CASE(ENOLCK);
#endif
#ifdef ENOLINK
ERRNO_CASE(ENOLINK);
#endif
#ifdef ENOMEM
ERRNO_CASE(ENOMEM);
#endif
#ifdef ENOMSG
ERRNO_CASE(ENOMSG);
#endif
#ifdef ENOPROTOOPT
ERRNO_CASE(ENOPROTOOPT);
#endif
#ifdef ENOSPC
ERRNO_CASE(ENOSPC);
#endif
#ifdef ENOSR
ERRNO_CASE(ENOSR);
#endif
#ifdef ENOSTR
ERRNO_CASE(ENOSTR);
#endif
#ifdef ENOSYS
ERRNO_CASE(ENOSYS);
#endif
#ifdef ENOTCONN
ERRNO_CASE(ENOTCONN);
#endif
#ifdef ENOTDIR
ERRNO_CASE(ENOTDIR);
#endif
#ifdef ENOTEMPTY
ERRNO_CASE(ENOTEMPTY);
#endif
#ifdef ENOTSOCK
ERRNO_CASE(ENOTSOCK);
#endif
#ifdef ENOTSUP
ERRNO_CASE(ENOTSUP);
#else
# ifdef EOPNOTSUPP
ERRNO_CASE(EOPNOTSUPP);
# endif
#endif
#ifdef ENOTTY
ERRNO_CASE(ENOTTY);
#endif
#ifdef ENXIO
ERRNO_CASE(ENXIO);
#endif
#ifdef EOVERFLOW
ERRNO_CASE(EOVERFLOW);
#endif
#ifdef EPERM
ERRNO_CASE(EPERM);
#endif
#ifdef EPIPE
ERRNO_CASE(EPIPE);
#endif
#ifdef EPROTO
ERRNO_CASE(EPROTO);
#endif
#ifdef EPROTONOSUPPORT
ERRNO_CASE(EPROTONOSUPPORT);
#endif
#ifdef EPROTOTYPE
ERRNO_CASE(EPROTOTYPE);
#endif
#ifdef ERANGE
ERRNO_CASE(ERANGE);
#endif
#ifdef EROFS
ERRNO_CASE(EROFS);
#endif
#ifdef ESPIPE
ERRNO_CASE(ESPIPE);
#endif
#ifdef ESRCH
ERRNO_CASE(ESRCH);
#endif
#ifdef ESTALE
ERRNO_CASE(ESTALE);
#endif
#ifdef ETIME
ERRNO_CASE(ETIME);
#endif
#ifdef ETIMEDOUT
ERRNO_CASE(ETIMEDOUT);
#endif
#ifdef ETXTBSY
ERRNO_CASE(ETXTBSY);
#endif
#ifdef EXDEV
ERRNO_CASE(EXDEV);
#endif
default: return "";
}
}
Local<Value> ErrnoException(int errorno,
const char *syscall,
const char *msg) {
Local<String> estring = String::NewSymbol(errno_string(errorno));
if (!msg[0]) msg = strerror(errorno);
Local<String> message = String::NewSymbol(msg);
Local<String> cons1 = String::Concat(estring, String::NewSymbol(", "));
Local<String> cons2 = String::Concat(cons1, message);
Local<Value> e = Exception::Error(cons2);
Local<Object> obj = e->ToObject();
if (errno_symbol.IsEmpty()) {
syscall_symbol = NODE_PSYMBOL("syscall");
errno_symbol = NODE_PSYMBOL("errno");
}
obj->Set(errno_symbol, Integer::New(errorno));
if (syscall) obj->Set(syscall_symbol, String::NewSymbol(syscall));
return e;
}
enum encoding ParseEncoding(Handle<Value> encoding_v, enum encoding _default) {
HandleScope scope;

4
src/node.h

@ -77,5 +77,9 @@ static inline void cb_destroy(v8::Persistent<v8::Function> * cb) {
delete cb;
}
v8::Local<v8::Value> ErrnoException(int errorno,
const char *syscall = NULL,
const char *msg = "");
} // namespace node
#endif // SRC_NODE_H_

6
src/node_cares.cc

@ -77,7 +77,6 @@ struct QueryArg {
Persistent<FunctionTemplate> Channel::constructor_template;
static Persistent<String> errno_symbol;
static Persistent<String> priority_symbol;
static Persistent<String> weight_symbol;
static Persistent<String> port_symbol;
@ -98,7 +97,6 @@ void Cares::Initialize(Handle<Object> target) {
target->Set(String::NewSymbol("SOCKET_BAD"), Integer::New(ARES_SOCKET_BAD));
errno_symbol = NODE_PSYMBOL("errno");
priority_symbol = NODE_PSYMBOL("priority");
weight_symbol = NODE_PSYMBOL("weight");
port_symbol = NODE_PSYMBOL("port");
@ -166,9 +164,7 @@ static Local<Array> HostEntToNames(struct hostent* hostent) {
static void ResolveError(Persistent<Function> &cb, int status) {
HandleScope scope;
Local<Value> e = Exception::Error(String::NewSymbol(ares_strerror(status)));
Local<Object> obj = e->ToObject();
obj->Set(errno_symbol, Integer::New(status));
Local<Value> e = ErrnoException(status, NULL, ares_strerror(status));
TryCatch try_catch;

17
src/node_crypto.cc

@ -352,23 +352,6 @@ static int verify_callback(int ok, X509_STORE_CTX *ctx) {
return(ok);
}
static inline Local<Value> ErrnoException(int errorno,
const char *syscall,
const char *msg = "") {
Local<String> estring = String::NewSymbol(errno_string(errorno));
if (!msg[0]) msg = strerror(errorno);
Local<String> message = String::NewSymbol(msg);
Local<String> cons1 = String::Concat(estring, String::NewSymbol(", "));
Local<String> cons2 = String::Concat(cons1, message);
Local<Value> e = Exception::Error(cons2);
Local<Object> obj = e->ToObject();
obj->Set(errno_symbol, Integer::New(errorno));
obj->Set(syscall_symbol, String::NewSymbol(syscall));
return e;
}
void SecureContext::Initialize(Handle<Object> target) {
HandleScope scope;

1
src/node_events.cc

@ -5,7 +5,6 @@
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

44
src/node_file.cc

@ -1,4 +1,5 @@
// Copyright 2009 Ryan Dahl <ry@tinyclouds.org>
#include <node.h>
#include <node_file.h>
#include <node_buffer.h>
@ -28,13 +29,6 @@ using namespace v8;
static Persistent<String> encoding_symbol;
static Persistent<String> errno_symbol;
static inline Local<Value> errno_exception(int errorno) {
Local<Value> e = Exception::Error(String::NewSymbol(strerror(errorno)));
Local<Object> obj = e->ToObject();
obj->Set(errno_symbol, Integer::New(errorno));
return e;
}
static int After(eio_req *req) {
HandleScope scope;
@ -47,7 +41,7 @@ static int After(eio_req *req) {
if (req->errorno != 0) {
argc = 1;
argv[0] = errno_exception(req->errorno);
argv[0] = ErrnoException(req->errorno);
} else {
// Note: the error is always given the first argument of the callback.
// If there is no error then then the first argument is null.
@ -171,7 +165,7 @@ static Handle<Value> Close(const Arguments& args) {
ASYNC_CALL(close, args[1], fd)
} else {
int ret = close(fd);
if (ret != 0) return ThrowException(errno_exception(errno));
if (ret != 0) return ThrowException(ErrnoException(errno));
return Undefined();
}
}
@ -190,7 +184,7 @@ static Handle<Value> Stat(const Arguments& args) {
} else {
struct stat s;
int ret = stat(*path, &s);
if (ret != 0) return ThrowException(errno_exception(errno));
if (ret != 0) return ThrowException(ErrnoException(errno));
return scope.Close(BuildStatsObject(&s));
}
}
@ -209,7 +203,7 @@ static Handle<Value> LStat(const Arguments& args) {
} else {
struct stat s;
int ret = lstat(*path, &s);
if (ret != 0) return ThrowException(errno_exception(errno));
if (ret != 0) return ThrowException(ErrnoException(errno));
return scope.Close(BuildStatsObject(&s));
}
}
@ -228,7 +222,7 @@ static Handle<Value> Symlink(const Arguments& args) {
ASYNC_CALL(symlink, args[2], *dest, *path)
} else {
int ret = symlink(*dest, *path);
if (ret != 0) return ThrowException(errno_exception(errno));
if (ret != 0) return ThrowException(ErrnoException(errno));
return Undefined();
}
}
@ -247,7 +241,7 @@ static Handle<Value> Link(const Arguments& args) {
ASYNC_CALL(link, args[2], *orig_path, *new_path)
} else {
int ret = link(*orig_path, *new_path);
if (ret != 0) return ThrowException(errno_exception(errno));
if (ret != 0) return ThrowException(ErrnoException(errno));
return Undefined();
}
}
@ -266,7 +260,7 @@ static Handle<Value> ReadLink(const Arguments& args) {
} else {
char buf[PATH_MAX];
ssize_t bz = readlink(*path, buf, PATH_MAX);
if (bz == -1) return ThrowException(errno_exception(errno));
if (bz == -1) return ThrowException(ErrnoException(errno));
return scope.Close(String::New(buf, bz));
}
}
@ -285,7 +279,7 @@ static Handle<Value> Rename(const Arguments& args) {
ASYNC_CALL(rename, args[2], *old_path, *new_path)
} else {
int ret = rename(*old_path, *new_path);
if (ret != 0) return ThrowException(errno_exception(errno));
if (ret != 0) return ThrowException(ErrnoException(errno));
return Undefined();
}
}
@ -304,7 +298,7 @@ static Handle<Value> Truncate(const Arguments& args) {
ASYNC_CALL(ftruncate, args[2], fd, len)
} else {
int ret = ftruncate(fd, len);
if (ret != 0) return ThrowException(errno_exception(errno));
if (ret != 0) return ThrowException(ErrnoException(errno));
return Undefined();
}
}
@ -322,7 +316,7 @@ static Handle<Value> Unlink(const Arguments& args) {
ASYNC_CALL(unlink, args[1], *path)
} else {
int ret = unlink(*path);
if (ret != 0) return ThrowException(errno_exception(errno));
if (ret != 0) return ThrowException(ErrnoException(errno));
return Undefined();
}
}
@ -340,7 +334,7 @@ static Handle<Value> RMDir(const Arguments& args) {
ASYNC_CALL(rmdir, args[1], *path)
} else {
int ret = rmdir(*path);
if (ret != 0) return ThrowException(errno_exception(errno));
if (ret != 0) return ThrowException(ErrnoException(errno));
return Undefined();
}
}
@ -359,7 +353,7 @@ static Handle<Value> MKDir(const Arguments& args) {
ASYNC_CALL(mkdir, args[2], *path, mode)
} else {
int ret = mkdir(*path, mode);
if (ret != 0) return ThrowException(errno_exception(errno));
if (ret != 0) return ThrowException(ErrnoException(errno));
return Undefined();
}
}
@ -384,7 +378,7 @@ static Handle<Value> SendFile(const Arguments& args) {
} else {
ssize_t sent = eio_sendfile_sync (out_fd, in_fd, in_offset, length);
// XXX is this the right errno to use?
if (sent < 0) return ThrowException(errno_exception(errno));
if (sent < 0) return ThrowException(ErrnoException(errno));
return Integer::New(sent);
}
}
@ -402,7 +396,7 @@ static Handle<Value> ReadDir(const Arguments& args) {
ASYNC_CALL(readdir, args[1], *path, 0 /*flags*/)
} else {
DIR *dir = opendir(*path);
if (!dir) return ThrowException(errno_exception(errno));
if (!dir) return ThrowException(ErrnoException(errno));
struct dirent *ent;
@ -443,7 +437,7 @@ static Handle<Value> Open(const Arguments& args) {
ASYNC_CALL(open, args[3], *path, flags, mode)
} else {
int fd = open(*path, flags, mode);
if (fd < 0) return ThrowException(errno_exception(errno));
if (fd < 0) return ThrowException(ErrnoException(errno));
return scope.Close(Integer::New(fd));
}
}
@ -561,7 +555,7 @@ static Handle<Value> Write(const Arguments& args) {
} else {
written = pwrite(fd, buf, len, pos);
}
if (written < 0) return ThrowException(errno_exception(errno));
if (written < 0) return ThrowException(ErrnoException(errno));
return scope.Close(Integer::New(written));
}
}
@ -600,7 +594,7 @@ static Handle<Value> Read(const Arguments& args) {
} else {
ret = pread(fd, buf, MIN(len, READ_BUF_LEN), offset);
}
if (ret < 0) return ThrowException(errno_exception(errno));
if (ret < 0) return ThrowException(ErrnoException(errno));
Local<Array> a = Array::New(2);
a->Set(Integer::New(0), Encode(buf, ret, encoding));
a->Set(Integer::New(1), Integer::New(ret));
@ -624,7 +618,7 @@ static Handle<Value> Chmod(const Arguments& args){
ASYNC_CALL(chmod, args[2], *path, mode);
} else {
int ret = chmod(*path, mode);
if (ret != 0) return ThrowException(errno_exception(errno));
if (ret != 0) return ThrowException(ErrnoException(errno));
return Undefined();
}
}

340
src/node_net2.cc

@ -55,346 +55,6 @@ static Persistent<FunctionTemplate> recv_msg_template;
}
static inline const char *errno_string(int errorno) {
#define ERRNO_CASE(e) case e: return #e;
switch (errorno) {
#ifdef EACCES
ERRNO_CASE(EACCES);
#endif
#ifdef EADDRINUSE
ERRNO_CASE(EADDRINUSE);
#endif
#ifdef EADDRNOTAVAIL
ERRNO_CASE(EADDRNOTAVAIL);
#endif
#ifdef EAFNOSUPPORT
ERRNO_CASE(EAFNOSUPPORT);
#endif
#ifdef EAGAIN
ERRNO_CASE(EAGAIN);
#else
# ifdef EWOULDBLOCK
ERRNO_CASE(EWOULDBLOCK);
# endif
#endif
#ifdef EALREADY
ERRNO_CASE(EALREADY);
#endif
#ifdef EBADF
ERRNO_CASE(EBADF);
#endif
#ifdef EBADMSG
ERRNO_CASE(EBADMSG);
#endif
#ifdef EBUSY
ERRNO_CASE(EBUSY);
#endif
#ifdef ECANCELED
ERRNO_CASE(ECANCELED);
#endif
#ifdef ECHILD
ERRNO_CASE(ECHILD);
#endif
#ifdef ECONNABORTED
ERRNO_CASE(ECONNABORTED);
#endif
#ifdef ECONNREFUSED
ERRNO_CASE(ECONNREFUSED);
#endif
#ifdef ECONNRESET
ERRNO_CASE(ECONNRESET);
#endif
#ifdef EDEADLK
ERRNO_CASE(EDEADLK);
#endif
#ifdef EDESTADDRREQ
ERRNO_CASE(EDESTADDRREQ);
#endif
#ifdef EDOM
ERRNO_CASE(EDOM);
#endif
#ifdef EDQUOT
ERRNO_CASE(EDQUOT);
#endif
#ifdef EEXIST
ERRNO_CASE(EEXIST);
#endif
#ifdef EFAULT
ERRNO_CASE(EFAULT);
#endif
#ifdef EFBIG
ERRNO_CASE(EFBIG);
#endif
#ifdef EHOSTUNREACH
ERRNO_CASE(EHOSTUNREACH);
#endif
#ifdef EIDRM
ERRNO_CASE(EIDRM);
#endif
#ifdef EILSEQ
ERRNO_CASE(EILSEQ);
#endif
#ifdef EINPROGRESS
ERRNO_CASE(EINPROGRESS);
#endif
#ifdef EINTR
ERRNO_CASE(EINTR);
#endif
#ifdef EINVAL
ERRNO_CASE(EINVAL);
#endif
#ifdef EIO
ERRNO_CASE(EIO);
#endif
#ifdef EISCONN
ERRNO_CASE(EISCONN);
#endif
#ifdef EISDIR
ERRNO_CASE(EISDIR);
#endif
#ifdef ELOOP
ERRNO_CASE(ELOOP);
#endif
#ifdef EMFILE
ERRNO_CASE(EMFILE);
#endif
#ifdef EMLINK
ERRNO_CASE(EMLINK);
#endif
#ifdef EMSGSIZE
ERRNO_CASE(EMSGSIZE);
#endif
#ifdef EMULTIHOP
ERRNO_CASE(EMULTIHOP);
#endif
#ifdef ENAMETOOLONG
ERRNO_CASE(ENAMETOOLONG);
#endif
#ifdef ENETDOWN
ERRNO_CASE(ENETDOWN);
#endif
#ifdef ENETRESET
ERRNO_CASE(ENETRESET);
#endif
#ifdef ENETUNREACH
ERRNO_CASE(ENETUNREACH);
#endif
#ifdef ENFILE
ERRNO_CASE(ENFILE);
#endif
#ifdef ENOBUFS
ERRNO_CASE(ENOBUFS);
#endif
#ifdef ENODATA
ERRNO_CASE(ENODATA);
#endif
#ifdef ENODEV
ERRNO_CASE(ENODEV);
#endif
#ifdef ENOENT
ERRNO_CASE(ENOENT);
#endif
#ifdef ENOEXEC
ERRNO_CASE(ENOEXEC);
#endif
#ifdef ENOLCK
ERRNO_CASE(ENOLCK);
#endif
#ifdef ENOLINK
ERRNO_CASE(ENOLINK);
#endif
#ifdef ENOMEM
ERRNO_CASE(ENOMEM);
#endif
#ifdef ENOMSG
ERRNO_CASE(ENOMSG);
#endif
#ifdef ENOPROTOOPT
ERRNO_CASE(ENOPROTOOPT);
#endif
#ifdef ENOSPC
ERRNO_CASE(ENOSPC);
#endif
#ifdef ENOSR
ERRNO_CASE(ENOSR);
#endif
#ifdef ENOSTR
ERRNO_CASE(ENOSTR);
#endif
#ifdef ENOSYS
ERRNO_CASE(ENOSYS);
#endif
#ifdef ENOTCONN
ERRNO_CASE(ENOTCONN);
#endif
#ifdef ENOTDIR
ERRNO_CASE(ENOTDIR);
#endif
#ifdef ENOTEMPTY
ERRNO_CASE(ENOTEMPTY);
#endif
#ifdef ENOTSOCK
ERRNO_CASE(ENOTSOCK);
#endif
#ifdef ENOTSUP
ERRNO_CASE(ENOTSUP);
#else
# ifdef EOPNOTSUPP
ERRNO_CASE(EOPNOTSUPP);
# endif
#endif
#ifdef ENOTTY
ERRNO_CASE(ENOTTY);
#endif
#ifdef ENXIO
ERRNO_CASE(ENXIO);
#endif
#ifdef EOVERFLOW
ERRNO_CASE(EOVERFLOW);
#endif
#ifdef EPERM
ERRNO_CASE(EPERM);
#endif
#ifdef EPIPE
ERRNO_CASE(EPIPE);
#endif
#ifdef EPROTO
ERRNO_CASE(EPROTO);
#endif
#ifdef EPROTONOSUPPORT
ERRNO_CASE(EPROTONOSUPPORT);
#endif
#ifdef EPROTOTYPE
ERRNO_CASE(EPROTOTYPE);
#endif
#ifdef ERANGE
ERRNO_CASE(ERANGE);
#endif
#ifdef EROFS
ERRNO_CASE(EROFS);
#endif
#ifdef ESPIPE
ERRNO_CASE(ESPIPE);
#endif
#ifdef ESRCH
ERRNO_CASE(ESRCH);
#endif
#ifdef ESTALE
ERRNO_CASE(ESTALE);
#endif
#ifdef ETIME
ERRNO_CASE(ETIME);
#endif
#ifdef ETIMEDOUT
ERRNO_CASE(ETIMEDOUT);
#endif
#ifdef ETXTBSY
ERRNO_CASE(ETXTBSY);
#endif
#ifdef EXDEV
ERRNO_CASE(EXDEV);
#endif
default: return "";
}
}
static inline Local<Value> ErrnoException(int errorno,
const char *syscall,
const char *msg = "") {
Local<String> estring = String::NewSymbol(errno_string(errorno));
if (!msg[0]) msg = strerror(errorno);
Local<String> message = String::NewSymbol(msg);
Local<String> cons1 = String::Concat(estring, String::NewSymbol(", "));
Local<String> cons2 = String::Concat(cons1, message);
Local<Value> e = Exception::Error(cons2);
Local<Object> obj = e->ToObject();
obj->Set(errno_symbol, Integer::New(errorno));
obj->Set(syscall_symbol, String::NewSymbol(syscall));
return e;
}
static inline bool SetCloseOnExec(int fd) {
return (fcntl(fd, F_SETFD, FD_CLOEXEC) != -1);

10
src/node_stdio.cc

@ -21,14 +21,6 @@ static int stdout_flags = -1;
static int stdin_flags = -1;
static Local<Value> errno_exception(int errorno) {
Local<Value> e = Exception::Error(String::NewSymbol(strerror(errorno)));
Local<Object> obj = e->ToObject();
obj->Set(String::NewSymbol("errno"), Integer::New(errorno));
return e;
}
/* STDERR IS ALWAY SYNC ALWAYS UTF8 */
static Handle<Value>
WriteError (const Arguments& args)
@ -49,7 +41,7 @@ WriteError (const Arguments& args)
usleep(100);
continue;
}
return ThrowException(errno_exception(errno));
return ThrowException(ErrnoException(errno, "write"));
}
written += (size_t)r;
}

Loading…
Cancel
Save