Browse Source

Basic VC++ compatibility work.

v0.7.4-release
Peter Bright 14 years ago
committed by Ryan Dahl
parent
commit
13d6a1f67f
  1. 6
      src/cares_wrap.cc
  2. 37
      src/node.cc
  3. 9
      src/node.h
  4. 11
      src/node_constants.cc
  5. 4
      src/node_extensions.cc
  6. 48
      src/node_file.cc
  7. 2
      src/node_javascript.cc
  8. 2
      src/platform_win32.cc
  9. 10
      src/platform_win32.h
  10. 2
      src/tcp_wrap.cc

6
src/cares_wrap.cc

@ -23,14 +23,14 @@
#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:

37
src/node.cc

@ -29,17 +29,31 @@
#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

9
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 <uv.h>

11
src/node_constants.cc

@ -24,17 +24,19 @@
#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);

4
src/node_extensions.cc

@ -23,6 +23,10 @@
#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

48
src/node_file.cc

@ -28,17 +28,28 @@
#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);
}

2
src/node_javascript.cc

@ -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;

2
src/platform_win32.cc

@ -27,8 +27,10 @@
#include <errno.h>
#include <stdlib.h>
#if defined(__MINGW32__)
#include <sys/param.h> // for MAXPATHLEN
#include <unistd.h> // getpagesize
#endif
#include <platform_win32.h>

10
src/platform_win32.h

@ -59,10 +59,16 @@
#include <windows.h>
#include <winsock2.h>
#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);

2
src/tcp_wrap.cc

@ -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>

Loading…
Cancel
Save