Skip to content

Commit 13d6a1f

Browse files
DrPizzary
authored andcommitted
Basic VC++ compatibility work.
1 parent bd270b4 commit 13d6a1f

File tree

10 files changed

+106
-25
lines changed

10 files changed

+106
-25
lines changed

src/cares_wrap.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
#include <node.h>
2424
#include <uv.h>
2525

26-
#if defined(__OpenBSD__) || defined(__MINGW32__)
26+
#if defined(__OpenBSD__) || defined(__MINGW32__) || defined(_MSC_VER)
2727
# include <nameser.h>
2828
#else
2929
# include <arpa/nameser.h>
3030
#endif
3131

3232
// Temporary hack: libuv should provide uv_inet_pton and uv_inet_ntop.
33-
#ifdef __MINGW32__
33+
#if defined(__MINGW32__) || defined(_MSC_VER)
3434
extern "C" {
3535
# include <inet_net_pton.h>
3636
# include <inet_ntop.h>
@@ -170,10 +170,12 @@ class QueryWrap {
170170
// Subclasses should implement the appropriate Send method.
171171
virtual int Send(const char* name) {
172172
assert(0);
173+
return 0;
173174
}
174175

175176
virtual int Send(const char* name, int family) {
176177
assert(0);
178+
return 0;
177179
}
178180

179181
protected:

src/node.cc

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,31 @@
2929
#include <locale.h>
3030
#include <signal.h>
3131
#include <stdio.h>
32+
#if defined(_MSC_VER)
33+
#define snprintf _snprintf
34+
#endif
3235
#include <stdlib.h>
33-
#include <strings.h>
3436
#include <string.h>
37+
#if !defined(_MSC_VER)
38+
#include <strings.h>
39+
#else
40+
#define strcasecmp _stricmp
41+
#endif
3542
#include <limits.h> /* PATH_MAX */
3643
#include <assert.h>
37-
#include <unistd.h>
44+
#if !defined(_MSC_VER)
45+
#include <unistd.h> /* setuid, getuid */
46+
#else
47+
#include <direct.h>
48+
#define chdir _chdir
49+
#define getcwd _getcwd
50+
#include <process.h>
51+
#define getpid _getpid
52+
#endif
3853
#include <errno.h>
3954
#include <sys/types.h>
40-
#include <unistd.h> /* setuid, getuid */
4155

42-
#ifdef __MINGW32__
56+
#if defined(__MINGW32__) || defined(_MSC_VER)
4357
# include <platform_win32.h> /* winapi_perror() */
4458
# ifdef PTW32_STATIC_LIB
4559
extern "C" {
@@ -69,13 +83,15 @@ extern "C" {
6983
# include <node_stat_watcher.h>
7084
# include <node_timer.h>
7185
#endif
86+
#if !defined(_MSC_VER)
7287
#include <node_child_process.h>
88+
#endif
7389
#include <node_constants.h>
7490
#include <node_stdio.h>
7591
#include <node_javascript.h>
7692
#include <node_version.h>
7793
#include <node_string.h>
78-
#ifdef HAVE_OPENSSL
94+
#if HAVE_OPENSSL
7995
# include <node_crypto.h>
8096
#endif
8197
#include <node_script.h>
@@ -87,7 +103,7 @@ using namespace v8;
87103
# ifdef __APPLE__
88104
# include <crt_externs.h>
89105
# define environ (*_NSGetEnviron())
90-
# else
106+
# elif !defined(_MSC_VER)
91107
extern char **environ;
92108
# endif
93109

@@ -2086,7 +2102,7 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
20862102
versions->Set(String::NewSymbol("ares"), String::New(ARES_VERSION_STR));
20872103
snprintf(buf, 20, "%d.%d", UV_VERSION_MAJOR, UV_VERSION_MINOR);
20882104
versions->Set(String::NewSymbol("uv"), String::New(buf));
2089-
#ifdef HAVE_OPENSSL
2105+
#if HAVE_OPENSSL
20902106
// Stupid code to slice out the version string.
20912107
int c, l = strlen(OPENSSL_VERSION_TEXT);
20922108
for (i = 0; i < l; i++) {
@@ -2154,13 +2170,14 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
21542170
}
21552171

21562172
size_t size = 2*PATH_MAX;
2157-
char execPath[size];
2173+
char* execPath = new char[size];
21582174
if (uv_exepath(execPath, &size) != 0) {
21592175
// as a last ditch effort, fallback on argv[0] ?
21602176
process->Set(String::NewSymbol("execPath"), String::New(argv[0]));
21612177
} else {
21622178
process->Set(String::NewSymbol("execPath"), String::New(execPath, size));
21632179
}
2180+
delete [] execPath;
21642181

21652182

21662183
// define various internal methods
@@ -2531,7 +2548,7 @@ void EmitExit(v8::Handle<v8::Object> process) {
25312548

25322549
int Start(int argc, char *argv[]) {
25332550

2534-
#if defined __MINGW32__ && defined PTW32_STATIC_LIB
2551+
#if (defined(__MINGW32__) || defined(_MSC_VER)) && defined(PTW32_STATIC_LIB)
25352552
pthread_win32_process_attach_np();
25362553
#endif
25372554

@@ -2568,7 +2585,7 @@ int Start(int argc, char *argv[]) {
25682585
V8::Dispose();
25692586
#endif // NDEBUG
25702587

2571-
#if defined __MINGW32__ && defined PTW32_STATIC_LIB
2588+
#if (defined(__MINGW32__) || defined(_MSC_VER)) && defined(PTW32_STATIC_LIB)
25722589
pthread_win32_process_detach_np();
25732590
#endif
25742591

src/node.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,17 @@
2525
// A dependency include (libeio\xthread.h) defines _WIN32_WINNT to another value
2626
// This should be defined in make system.
2727
// See issue https://github.com/joyent/node/issues/1236
28-
#ifdef __MINGW32__
28+
#if defined(__MINGW32__) || defined(_MSC_VER)
2929
#ifndef _WIN32_WINNT
3030
# define _WIN32_WINNT 0x0501
3131
#endif
32+
33+
#define NOMINMAX
34+
35+
#endif
36+
37+
#if defined(_MSC_VER)
38+
#define PATH_MAX MAX_PATH
3239
#endif
3340

3441
#include <uv.h>

src/node_constants.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@
2424
#include <uv.h>
2525

2626
#include <errno.h>
27+
#if !defined(_MSC_VER)
2728
#include <unistd.h>
29+
#endif
2830
#include <fcntl.h>
2931
#include <signal.h>
3032
#include <sys/types.h>
3133
#include <sys/stat.h>
3234

33-
#ifdef __MINGW32__
35+
#if defined(__MINGW32__) || defined(_MSC_VER)
3436
# include <platform_win32.h>
3537
#endif
3638

37-
#ifdef HAVE_OPENSSL
39+
#if HAVE_OPENSSL
3840
# include <openssl/ssl.h>
3941
#endif
4042

@@ -52,8 +54,13 @@ void DefineConstants(Handle<Object> target) {
5254
NODE_DEFINE_CONSTANT(target, S_IFREG);
5355
NODE_DEFINE_CONSTANT(target, S_IFDIR);
5456
NODE_DEFINE_CONSTANT(target, S_IFCHR);
57+
#ifdef S_IFBLK
5558
NODE_DEFINE_CONSTANT(target, S_IFBLK);
59+
#endif
60+
61+
#ifdef S_IFIFO
5662
NODE_DEFINE_CONSTANT(target, S_IFIFO);
63+
#endif
5764

5865
#ifdef S_IFLNK
5966
NODE_DEFINE_CONSTANT(target, S_IFLNK);

src/node_extensions.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#include "node.h"
2424
#include "node_version.h"
2525
#include <string.h>
26+
#include <stdio.h>
27+
#if defined(_MSC_VER)
28+
#define snprintf _snprintf
29+
#endif
2630

2731
#undef NODE_EXT_LIST_START
2832
#undef NODE_EXT_LIST_ITEM

src/node_file.cc

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,28 @@
2828

2929
#include <sys/types.h>
3030
#include <sys/stat.h>
31+
#if !defined(_MSC_VER)
3132
#include <sys/time.h>
3233
#include <dirent.h>
34+
#endif
3335
#include <fcntl.h>
3436
#include <stdlib.h>
37+
#if !defined(_MSC_VER)
3538
#include <unistd.h>
39+
#else
40+
#include <direct.h>
41+
#define chdir _chdir
42+
#define rmdir _rmdir
43+
#define mkdir _mkdir
44+
#include <io.h>
45+
#define ftruncate _chsize
46+
#endif
3647
#include <assert.h>
3748
#include <string.h>
3849
#include <errno.h>
3950
#include <limits.h>
4051

41-
#ifdef __MINGW32__
52+
#if defined(__MINGW32__) || defined(_MSC_VER)
4253
# include <platform_win32.h>
4354
#endif
4455

@@ -49,7 +60,7 @@
4960

5061
/* HACK to use pread/pwrite from eio because MINGW32 doesn't have it */
5162
/* TODO fixme */
52-
#ifdef __MINGW32__
63+
#if defined(__MINGW32__) || defined(_MSC_VER)
5364
# define pread eio__pread
5465
# define pwrite eio__pwrite
5566
#endif
@@ -515,7 +526,7 @@ static Handle<Value> Fdatasync(const Arguments& args) {
515526
} else {
516527
#if HAVE_FDATASYNC
517528
int ret = fdatasync(fd);
518-
#elif defined(__MINGW32__)
529+
#elif defined(__MINGW32__) || defined(_MSC_VER)
519530
int ret = FlushFileBuffers((HANDLE)_get_osfhandle(fd)) ? 0 : -1;
520531
#else
521532
int ret = fsync(fd);
@@ -537,7 +548,7 @@ static Handle<Value> Fsync(const Arguments& args) {
537548
if (args[1]->IsFunction()) {
538549
ASYNC_CALL(fsync, args[1], fd)
539550
} else {
540-
#ifdef __MINGW32__
551+
#if defined(__MINGW32__) || defined(_MSC_VER)
541552
int ret = FlushFileBuffers((HANDLE)_get_osfhandle(fd)) ? 0 : -1;
542553
#else
543554
int ret = fsync(fd);
@@ -596,7 +607,7 @@ static Handle<Value> MKDir(const Arguments& args) {
596607
if (args[2]->IsFunction()) {
597608
ASYNC_CALL(mkdir, args[2], *path, mode)
598609
} else {
599-
#ifdef __MINGW32__
610+
#if defined(__MINGW32__) || defined(_MSC_VER)
600611
int ret = mkdir(*path);
601612
#else
602613
int ret = mkdir(*path, mode);
@@ -644,25 +655,48 @@ static Handle<Value> ReadDir(const Arguments& args) {
644655
if (args[1]->IsFunction()) {
645656
ASYNC_CALL(readdir, args[1], *path, 0 /*flags*/)
646657
} else {
658+
#if defined(__POSIX__)
647659
DIR *dir = opendir(*path);
648660
if (!dir) return ThrowException(ErrnoException(errno, NULL, "", *path));
649-
650661
struct dirent *ent;
662+
#else
663+
WIN32_FIND_DATAA ent = {0};
664+
size_t len = strlen(*path);
665+
const char* fmt = !len ? "./*"
666+
: ((*path)[len - 1] == '/' || (*path)[len - 1] == '\\') ? "%s*"
667+
: "%s\\*";
668+
char* path2 = new char[len + 4];
669+
sprintf(path2, fmt, *path);
670+
HANDLE dir = FindFirstFileA(path2, &ent);
671+
delete [] path2;
672+
if(dir == INVALID_HANDLE_VALUE) return ThrowException(ErrnoException(GetLastError(), "FindFirstFileA", "", path2));
673+
#endif
651674

652675
Local<Array> files = Array::New();
653676
char *name;
654677
int i = 0;
655678

679+
#if defined(__POSIX__)
656680
while ((ent = readdir(dir))) {
657681
name = ent->d_name;
658-
682+
#else
683+
do {
684+
name = ent.cFileName;
685+
#endif
659686
if (name[0] != '.' || (name[1] && (name[1] != '.' || name[2]))) {
660687
files->Set(Integer::New(i), String::New(name));
661688
i++;
662689
}
663690
}
691+
#if !defined(__POSIX__)
692+
while(FindNextFileA(dir, &ent));
693+
#endif
664694

695+
#if defined(__POSIX__)
665696
closedir(dir);
697+
#else
698+
FindClose(dir);
699+
#endif
666700

667701
return scope.Close(files);
668702
}

src/node_javascript.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
#include "node_natives.h"
2525
#include "node_string.h"
2626
#include <string.h>
27+
#if !defined(_MSC_VER)
2728
#include <strings.h>
29+
#endif
2830

2931
using namespace v8;
3032

src/platform_win32.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727

2828
#include <errno.h>
2929
#include <stdlib.h>
30+
#if defined(__MINGW32__)
3031
#include <sys/param.h> // for MAXPATHLEN
3132
#include <unistd.h> // getpagesize
33+
#endif
3234

3335
#include <platform_win32.h>
3436

src/platform_win32.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,16 @@
5959
#include <windows.h>
6060
#include <winsock2.h>
6161

62+
#if defined(_MSC_VER)
63+
#define STDIN_FILENO 0
64+
#define STDOUT_FILENO 1
65+
#define STDERR_FILENO 2
66+
#endif
67+
6268
namespace node {
6369

64-
#define NO_IMPL_MSG(name...) \
65-
fprintf(stderr, "Not implemented: %s\n", #name);
70+
#define NO_IMPL_MSG(...) \
71+
fprintf(stderr, "Not implemented: %s\n", #__VA_ARGS__);
6672

6773
const char *winapi_strerror(const int errorno);
6874
void winapi_perror(const char* prefix);

src/tcp_wrap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <stream_wrap.h>
66

77
// Temporary hack: libuv should provide uv_inet_pton and uv_inet_ntop.
8-
#ifdef __MINGW32__
8+
#if defined(__MINGW32__) || defined(_MSC_VER)
99
extern "C" {
1010
# include <inet_net_pton.h>
1111
# include <inet_ntop.h>

0 commit comments

Comments
 (0)