diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 0194d3b2bd..f7c82f4c20 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -23,14 +23,14 @@ #include #include -#if defined(__OpenBSD__) || defined(__MINGW32__) +#if defined(__OpenBSD__) || defined(__MINGW32__) || defined(_MSC_VER) # include #else # include #endif // Temporary hack: libuv should provide uv_inet_pton and uv_inet_ntop. -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(_MSC_VER) extern "C" { # include # include @@ -170,10 +170,12 @@ class QueryWrap { // Subclasses should implement the appropriate Send method. virtual int Send(const char* name) { assert(0); + return 0; } virtual int Send(const char* name, int family) { assert(0); + return 0; } protected: diff --git a/src/node.cc b/src/node.cc index 384d39aabd..bbb46e1202 100644 --- a/src/node.cc +++ b/src/node.cc @@ -29,17 +29,31 @@ #include #include #include +#if defined(_MSC_VER) +#define snprintf _snprintf +#endif #include -#include #include +#if !defined(_MSC_VER) +#include +#else +#define strcasecmp _stricmp +#endif #include /* PATH_MAX */ #include -#include +#if !defined(_MSC_VER) +#include /* setuid, getuid */ +#else +#include +#define chdir _chdir +#define getcwd _getcwd +#include +#define getpid _getpid +#endif #include #include -#include /* setuid, getuid */ -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(_MSC_VER) # include /* winapi_perror() */ # ifdef PTW32_STATIC_LIB extern "C" { @@ -69,13 +83,15 @@ extern "C" { # include # include #endif +#if !defined(_MSC_VER) #include +#endif #include #include #include #include #include -#ifdef HAVE_OPENSSL +#if HAVE_OPENSSL # include #endif #include @@ -87,7 +103,7 @@ using namespace v8; # ifdef __APPLE__ # include # define environ (*_NSGetEnviron()) -# else +# elif !defined(_MSC_VER) extern char **environ; # endif @@ -2086,7 +2102,7 @@ Handle SetupProcessObject(int argc, char *argv[]) { versions->Set(String::NewSymbol("ares"), String::New(ARES_VERSION_STR)); snprintf(buf, 20, "%d.%d", UV_VERSION_MAJOR, UV_VERSION_MINOR); versions->Set(String::NewSymbol("uv"), String::New(buf)); -#ifdef HAVE_OPENSSL +#if HAVE_OPENSSL // Stupid code to slice out the version string. int c, l = strlen(OPENSSL_VERSION_TEXT); for (i = 0; i < l; i++) { @@ -2154,13 +2170,14 @@ Handle SetupProcessObject(int argc, char *argv[]) { } size_t size = 2*PATH_MAX; - char execPath[size]; + char* execPath = new char[size]; if (uv_exepath(execPath, &size) != 0) { // as a last ditch effort, fallback on argv[0] ? process->Set(String::NewSymbol("execPath"), String::New(argv[0])); } else { process->Set(String::NewSymbol("execPath"), String::New(execPath, size)); } + delete [] execPath; // define various internal methods @@ -2531,7 +2548,7 @@ void EmitExit(v8::Handle process) { int Start(int argc, char *argv[]) { -#if defined __MINGW32__ && defined PTW32_STATIC_LIB +#if (defined(__MINGW32__) || defined(_MSC_VER)) && defined(PTW32_STATIC_LIB) pthread_win32_process_attach_np(); #endif @@ -2568,7 +2585,7 @@ int Start(int argc, char *argv[]) { V8::Dispose(); #endif // NDEBUG -#if defined __MINGW32__ && defined PTW32_STATIC_LIB +#if (defined(__MINGW32__) || defined(_MSC_VER)) && defined(PTW32_STATIC_LIB) pthread_win32_process_detach_np(); #endif diff --git a/src/node.h b/src/node.h index cf2980d1ae..9e816e0c7c 100644 --- a/src/node.h +++ b/src/node.h @@ -25,10 +25,17 @@ // A dependency include (libeio\xthread.h) defines _WIN32_WINNT to another value // This should be defined in make system. // See issue https://github.com/joyent/node/issues/1236 -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(_MSC_VER) #ifndef _WIN32_WINNT # define _WIN32_WINNT 0x0501 #endif + +#define NOMINMAX + +#endif + +#if defined(_MSC_VER) +#define PATH_MAX MAX_PATH #endif #include diff --git a/src/node_constants.cc b/src/node_constants.cc index 326bf264ff..6ac24a2c17 100644 --- a/src/node_constants.cc +++ b/src/node_constants.cc @@ -24,17 +24,19 @@ #include #include +#if !defined(_MSC_VER) #include +#endif #include #include #include #include -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(_MSC_VER) # include #endif -#ifdef HAVE_OPENSSL +#if HAVE_OPENSSL # include #endif @@ -52,8 +54,13 @@ void DefineConstants(Handle target) { NODE_DEFINE_CONSTANT(target, S_IFREG); NODE_DEFINE_CONSTANT(target, S_IFDIR); NODE_DEFINE_CONSTANT(target, S_IFCHR); +#ifdef S_IFBLK NODE_DEFINE_CONSTANT(target, S_IFBLK); +#endif + +#ifdef S_IFIFO NODE_DEFINE_CONSTANT(target, S_IFIFO); +#endif #ifdef S_IFLNK NODE_DEFINE_CONSTANT(target, S_IFLNK); diff --git a/src/node_extensions.cc b/src/node_extensions.cc index fb46a1d930..4b49f4ffb7 100644 --- a/src/node_extensions.cc +++ b/src/node_extensions.cc @@ -23,6 +23,10 @@ #include "node.h" #include "node_version.h" #include +#include +#if defined(_MSC_VER) +#define snprintf _snprintf +#endif #undef NODE_EXT_LIST_START #undef NODE_EXT_LIST_ITEM diff --git a/src/node_file.cc b/src/node_file.cc index e9a0b0ce5e..3485cfbcec 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -28,17 +28,28 @@ #include #include +#if !defined(_MSC_VER) #include #include +#endif #include #include +#if !defined(_MSC_VER) #include +#else +#include +#define chdir _chdir +#define rmdir _rmdir +#define mkdir _mkdir +#include +#define ftruncate _chsize +#endif #include #include #include #include -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(_MSC_VER) # include #endif @@ -49,7 +60,7 @@ /* HACK to use pread/pwrite from eio because MINGW32 doesn't have it */ /* TODO fixme */ -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(_MSC_VER) # define pread eio__pread # define pwrite eio__pwrite #endif @@ -515,7 +526,7 @@ static Handle Fdatasync(const Arguments& args) { } else { #if HAVE_FDATASYNC int ret = fdatasync(fd); -#elif defined(__MINGW32__) +#elif defined(__MINGW32__) || defined(_MSC_VER) int ret = FlushFileBuffers((HANDLE)_get_osfhandle(fd)) ? 0 : -1; #else int ret = fsync(fd); @@ -537,7 +548,7 @@ static Handle Fsync(const Arguments& args) { if (args[1]->IsFunction()) { ASYNC_CALL(fsync, args[1], fd) } else { -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(_MSC_VER) int ret = FlushFileBuffers((HANDLE)_get_osfhandle(fd)) ? 0 : -1; #else int ret = fsync(fd); @@ -596,7 +607,7 @@ static Handle MKDir(const Arguments& args) { if (args[2]->IsFunction()) { ASYNC_CALL(mkdir, args[2], *path, mode) } else { -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(_MSC_VER) int ret = mkdir(*path); #else int ret = mkdir(*path, mode); @@ -644,25 +655,48 @@ static Handle ReadDir(const Arguments& args) { if (args[1]->IsFunction()) { ASYNC_CALL(readdir, args[1], *path, 0 /*flags*/) } else { +#if defined(__POSIX__) DIR *dir = opendir(*path); if (!dir) return ThrowException(ErrnoException(errno, NULL, "", *path)); - struct dirent *ent; +#else + WIN32_FIND_DATAA ent = {0}; + size_t len = strlen(*path); + const char* fmt = !len ? "./*" + : ((*path)[len - 1] == '/' || (*path)[len - 1] == '\\') ? "%s*" + : "%s\\*"; + char* path2 = new char[len + 4]; + sprintf(path2, fmt, *path); + HANDLE dir = FindFirstFileA(path2, &ent); + delete [] path2; + if(dir == INVALID_HANDLE_VALUE) return ThrowException(ErrnoException(GetLastError(), "FindFirstFileA", "", path2)); +#endif Local files = Array::New(); char *name; int i = 0; +#if defined(__POSIX__) while ((ent = readdir(dir))) { name = ent->d_name; - +#else + do { + name = ent.cFileName; +#endif if (name[0] != '.' || (name[1] && (name[1] != '.' || name[2]))) { files->Set(Integer::New(i), String::New(name)); i++; } } +#if !defined(__POSIX__) + while(FindNextFileA(dir, &ent)); +#endif +#if defined(__POSIX__) closedir(dir); +#else + FindClose(dir); +#endif return scope.Close(files); } diff --git a/src/node_javascript.cc b/src/node_javascript.cc index f1ec3355df..2aef03501b 100644 --- a/src/node_javascript.cc +++ b/src/node_javascript.cc @@ -24,7 +24,9 @@ #include "node_natives.h" #include "node_string.h" #include +#if !defined(_MSC_VER) #include +#endif using namespace v8; diff --git a/src/platform_win32.cc b/src/platform_win32.cc index b6b94c7cf7..d1c88d0f7b 100644 --- a/src/platform_win32.cc +++ b/src/platform_win32.cc @@ -27,8 +27,10 @@ #include #include +#if defined(__MINGW32__) #include // for MAXPATHLEN #include // getpagesize +#endif #include diff --git a/src/platform_win32.h b/src/platform_win32.h index a2fcb1cbb6..ff6ea6c6b1 100644 --- a/src/platform_win32.h +++ b/src/platform_win32.h @@ -59,10 +59,16 @@ #include #include +#if defined(_MSC_VER) +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 +#endif + namespace node { -#define NO_IMPL_MSG(name...) \ - fprintf(stderr, "Not implemented: %s\n", #name); +#define NO_IMPL_MSG(...) \ + fprintf(stderr, "Not implemented: %s\n", #__VA_ARGS__); const char *winapi_strerror(const int errorno); void winapi_perror(const char* prefix); diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 7ac5d86d35..7e6e152cbf 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -5,7 +5,7 @@ #include // Temporary hack: libuv should provide uv_inet_pton and uv_inet_ntop. -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(_MSC_VER) extern "C" { # include # include