Basic VC++ compatibility work.
authorPeter Bright <drpizza@quiscalusmexicanus.org>
Sat, 6 Aug 2011 04:23:25 +0000 (05:23 +0100)
committerRyan Dahl <ry@tinyclouds.org>
Sat, 6 Aug 2011 10:31:29 +0000 (03:31 -0700)
src/cares_wrap.cc
src/node.cc
src/node.h
src/node_constants.cc
src/node_extensions.cc
src/node_file.cc
src/node_javascript.cc
src/platform_win32.cc
src/platform_win32.h
src/tcp_wrap.cc

index 0194d3b2bdc6980d5994ed504d496213dea911be..f7c82f4c201528e43ca4361171184bf6613534dd 100644 (file)
 #include <node.h>
 #include <uv.h>
 
-#if defined(__OpenBSD__) || defined(__MINGW32__)
+#if defined(__OpenBSD__) || defined(__MINGW32__) || defined(_MSC_VER)
 # include <nameser.h>
 #else
 # include <arpa/nameser.h>
 #endif
 
 // Temporary hack: libuv should provide uv_inet_pton and uv_inet_ntop.
-#ifdef __MINGW32__
+#if defined(__MINGW32__) || defined(_MSC_VER)
   extern "C" {
 #   include <inet_net_pton.h>
 #   include <inet_ntop.h>
@@ -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:
index 384d39aabd8e64dba5b297880eafd6e40009ce8d..bbb46e1202f6ce94afe2d3518f72d5dc3a51dd42 100644 (file)
 #include <locale.h>
 #include <signal.h>
 #include <stdio.h>
+#if defined(_MSC_VER)
+#define snprintf _snprintf
+#endif
 #include <stdlib.h>
-#include <strings.h>
 #include <string.h>
+#if !defined(_MSC_VER)
+#include <strings.h>
+#else
+#define strcasecmp _stricmp
+#endif
 #include <limits.h> /* PATH_MAX */
 #include <assert.h>
-#include <unistd.h>
+#if !defined(_MSC_VER)
+#include <unistd.h> /* setuid, getuid */
+#else
+#include <direct.h>
+#define chdir _chdir
+#define getcwd _getcwd
+#include <process.h>
+#define getpid _getpid
+#endif
 #include <errno.h>
 #include <sys/types.h>
-#include <unistd.h> /* setuid, getuid */
 
-#ifdef __MINGW32__
+#if defined(__MINGW32__) || defined(_MSC_VER)
 # include <platform_win32.h> /* winapi_perror() */
 # ifdef PTW32_STATIC_LIB
 extern "C" {
@@ -69,13 +83,15 @@ extern "C" {
 # include <node_stat_watcher.h>
 # include <node_timer.h>
 #endif
+#if !defined(_MSC_VER)
 #include <node_child_process.h>
+#endif
 #include <node_constants.h>
 #include <node_stdio.h>
 #include <node_javascript.h>
 #include <node_version.h>
 #include <node_string.h>
-#ifdef HAVE_OPENSSL
+#if HAVE_OPENSSL
 # include <node_crypto.h>
 #endif
 #include <node_script.h>
@@ -87,7 +103,7 @@ using namespace v8;
 # ifdef __APPLE__
 # include <crt_externs.h>
 # define environ (*_NSGetEnviron())
-# else
+# elif !defined(_MSC_VER)
 extern char **environ;
 # endif
 
@@ -2086,7 +2102,7 @@ Handle<Object> 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<Object> 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<v8::Object> 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
 
index cf2980d1ae63ff0fe323a11fcbdec4808f3d914e..9e816e0c7ca8c1ea51078e7399cc19f98daea63e 100644 (file)
 // 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 <uv.h>
index 326bf264ff31e8bb1835dafc5c6e9b5b9f8b19e1..6ac24a2c1729a56f61927b6226b20a522c343fff 100644 (file)
 #include <uv.h>
 
 #include <errno.h>
+#if !defined(_MSC_VER)
 #include <unistd.h>
+#endif
 #include <fcntl.h>
 #include <signal.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#ifdef __MINGW32__
+#if defined(__MINGW32__) || defined(_MSC_VER)
 # include <platform_win32.h>
 #endif
 
-#ifdef HAVE_OPENSSL
+#if HAVE_OPENSSL
 # include <openssl/ssl.h>
 #endif
 
@@ -52,8 +54,13 @@ void DefineConstants(Handle<Object> 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);
index fb46a1d930f017f535f0a49a974b7a9941768976..4b49f4ffb7cd14df9b85e7acd47fa48340bf7a21 100644 (file)
 #include "node.h"
 #include "node_version.h"
 #include <string.h>
+#include <stdio.h>
+#if defined(_MSC_VER)
+#define snprintf _snprintf
+#endif
 
 #undef NODE_EXT_LIST_START
 #undef NODE_EXT_LIST_ITEM
index e9a0b0ce5e27f1796d2d4600c4fc88d9de263a5c..3485cfbcec9ea5b55e5f4db2b552780cd5a1df8d 100644 (file)
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#if !defined(_MSC_VER)
 #include <sys/time.h>
 #include <dirent.h>
+#endif
 #include <fcntl.h>
 #include <stdlib.h>
+#if !defined(_MSC_VER)
 #include <unistd.h>
+#else
+#include <direct.h>
+#define chdir _chdir
+#define rmdir _rmdir
+#define mkdir _mkdir
+#include <io.h>
+#define ftruncate _chsize
+#endif
 #include <assert.h>
 #include <string.h>
 #include <errno.h>
 #include <limits.h>
 
-#ifdef __MINGW32__
+#if defined(__MINGW32__) || defined(_MSC_VER)
 # include <platform_win32.h>
 #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<Value> 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<Value> 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<Value> 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<Value> 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<Array> 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);
   }
index f1ec3355df8a5d9f7aeab44dcc8fc90578ffde38..2aef03501b0647eaa5725968f443eb23d9100b89 100644 (file)
@@ -24,7 +24,9 @@
 #include "node_natives.h"
 #include "node_string.h"
 #include <string.h>
+#if !defined(_MSC_VER)
 #include <strings.h>
+#endif
 
 using namespace v8;
 
index b6b94c7cf727e53504e0cd40bf1cb205f9f30a63..d1c88d0f7b9db8919981c67ab5572651e2293532 100644 (file)
 
 #include <errno.h>
 #include <stdlib.h>
+#if defined(__MINGW32__)
 #include <sys/param.h> // for MAXPATHLEN
 #include <unistd.h> // getpagesize
+#endif
 
 #include <platform_win32.h>
 
index a2fcb1cbb6880fe88105da9650b1cb2c79c299aa..ff6ea6c6b11a1f01cdb748f05ebe0da2020e81ed 100644 (file)
 #include <windows.h>
 #include <winsock2.h>
 \r
+#if defined(_MSC_VER)
+#define STDIN_FILENO 0
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
+#endif
+
 namespace node {\r
 \r
-#define NO_IMPL_MSG(name...) \\r
-    fprintf(stderr, "Not implemented: %s\n", #name);\r
+#define NO_IMPL_MSG(...) \\r
+    fprintf(stderr, "Not implemented: %s\n", #__VA_ARGS__);\r
 \r
 const char *winapi_strerror(const int errorno);\r
 void winapi_perror(const char* prefix);\r
index 7ac5d86d3553fc1fe6b201ca3a9daf0c8c515dab..7e6e152cbfd257a4034174763d11e2513113b635 100644 (file)
@@ -5,7 +5,7 @@
 #include <stream_wrap.h>
 
 // Temporary hack: libuv should provide uv_inet_pton and uv_inet_ntop.
-#ifdef __MINGW32__
+#if defined(__MINGW32__) || defined(_MSC_VER)
   extern "C" {
 #   include <inet_net_pton.h>
 #   include <inet_ntop.h>