Browse Source

Use unicode and bigfile aware stat/fstat

v0.7.4-release
Bert Belder 14 years ago
parent
commit
f48c36f74f
  1. 14
      src/node.h
  2. 16
      src/node_file.cc

14
src/node.h

@ -63,7 +63,19 @@ ssize_t DecodeWrite(char *buf,
v8::Handle<v8::Value>, v8::Handle<v8::Value>,
enum encoding encoding = BINARY); enum encoding encoding = BINARY);
v8::Local<v8::Object> BuildStatsObject(struct stat * s); // Use different stat structs & calls on windows and posix;
// on windows, _stati64 is utf-8 and big file aware.
#if __POSIX__
# define NODE_STAT stat
# define NODE_FSTAT fstat
# define NODE_STAT_STRUCT struct stat
#else // __MINGW32__
# define NODE_STAT _stati64
# define NODE_FSTAT _fstati64
# define NODE_STAT_STRUCT struct _stati64
#endif
v8::Local<v8::Object> BuildStatsObject(NODE_STAT_STRUCT *s);
/** /**

16
src/node_file.cc

@ -26,7 +26,7 @@
/* HACK to use pread/pwrite from eio because MINGW32 doesn't have it /* /* HACK to use pread/pwrite from eio because MINGW32 doesn't have it /*
/* TODO fixme */ /* TODO fixme */
#if __MINGW32__ #ifdef __MINGW32__
# define pread eio__pread # define pread eio__pread
# define pwrite eio__pwrite # define pwrite eio__pwrite
#endif #endif
@ -109,7 +109,7 @@ static int After(eio_req *req) {
case EIO_LSTAT: case EIO_LSTAT:
case EIO_FSTAT: case EIO_FSTAT:
{ {
struct stat *s = reinterpret_cast<struct stat*>(req->ptr2); NODE_STAT_STRUCT *s = reinterpret_cast<NODE_STAT_STRUCT*>(req->ptr2);
argv[1] = BuildStatsObject(s); argv[1] = BuildStatsObject(s);
} }
break; break;
@ -207,7 +207,7 @@ static Persistent<String> atime_symbol;
static Persistent<String> mtime_symbol; static Persistent<String> mtime_symbol;
static Persistent<String> ctime_symbol; static Persistent<String> ctime_symbol;
Local<Object> BuildStatsObject(struct stat * s) { Local<Object> BuildStatsObject(NODE_STAT_STRUCT *s) {
HandleScope scope; HandleScope scope;
if (dev_symbol.IsEmpty()) { if (dev_symbol.IsEmpty()) {
@ -285,8 +285,8 @@ static Handle<Value> Stat(const Arguments& args) {
if (args[1]->IsFunction()) { if (args[1]->IsFunction()) {
ASYNC_CALL(stat, args[1], *path) ASYNC_CALL(stat, args[1], *path)
} else { } else {
struct stat s; NODE_STAT_STRUCT s;
int ret = stat(*path, &s); int ret = NODE_STAT(*path, &s);
if (ret != 0) return ThrowException(ErrnoException(errno, NULL, "", *path)); if (ret != 0) return ThrowException(ErrnoException(errno, NULL, "", *path));
return scope.Close(BuildStatsObject(&s)); return scope.Close(BuildStatsObject(&s));
} }
@ -305,7 +305,7 @@ static Handle<Value> LStat(const Arguments& args) {
if (args[1]->IsFunction()) { if (args[1]->IsFunction()) {
ASYNC_CALL(lstat, args[1], *path) ASYNC_CALL(lstat, args[1], *path)
} else { } else {
struct stat s; NODE_STAT_STRUCT s;
int ret = lstat(*path, &s); int ret = lstat(*path, &s);
if (ret != 0) return ThrowException(ErrnoException(errno, NULL, "", *path)); if (ret != 0) return ThrowException(ErrnoException(errno, NULL, "", *path));
return scope.Close(BuildStatsObject(&s)); return scope.Close(BuildStatsObject(&s));
@ -325,8 +325,8 @@ static Handle<Value> FStat(const Arguments& args) {
if (args[1]->IsFunction()) { if (args[1]->IsFunction()) {
ASYNC_CALL(fstat, args[1], fd) ASYNC_CALL(fstat, args[1], fd)
} else { } else {
struct stat s; NODE_STAT_STRUCT s;
int ret = fstat(fd, &s); int ret = NODE_FSTAT(fd, &s);
if (ret != 0) return ThrowException(ErrnoException(errno)); if (ret != 0) return ThrowException(ErrnoException(errno));
return scope.Close(BuildStatsObject(&s)); return scope.Close(BuildStatsObject(&s));
} }

Loading…
Cancel
Save