From c3ffbf219ca8049c901ec58d4d4b3df5b96c5097 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Sun, 2 Jan 2011 23:44:43 +0100 Subject: [PATCH] Fix the OS module for win32 --- src/node_os.cc | 21 ++++++++++++++++++++- src/platform_win32.cc | 40 +++++++++++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/src/node_os.cc b/src/node_os.cc index 9765955d864..758648835e0 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -12,6 +12,7 @@ # include // gethostname, sysconf # include #else // __MINGW32__ +# include // GetVersionEx # include // gethostname #endif // __MINGW32__ @@ -36,6 +37,8 @@ static Handle GetHostname(const Arguments& args) { static Handle GetOSType(const Arguments& args) { HandleScope scope; + +#ifdef __POSIX__ char type[256]; struct utsname info; @@ -44,17 +47,33 @@ static Handle GetOSType(const Arguments& args) { type[strlen(info.sysname)] = 0; return scope.Close(String::New(type)); +#else // __MINGW32__ + return scope.Close(String::New("Windows_NT")); +#endif } static Handle GetOSRelease(const Arguments& args) { HandleScope scope; char release[256]; + +#ifdef __POSIX__ struct utsname info; uname(&info); strncpy(release, info.release, strlen(info.release)); release[strlen(info.release)] = 0; +#else // __MINGW32__ + OSVERSIONINFO info; + info.dwOSVersionInfoSize = sizeof(info); + + if (GetVersionEx(&info) == 0) { + return Undefined(); + } + + sprintf(release, "%d.%d.%d", info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber); +#endif + return scope.Close(String::New(release)); } @@ -131,4 +150,4 @@ void OS::Initialize(v8::Handle target) { } // namespace node -NODE_MODULE(node_os, node::OS::Initialize); \ No newline at end of file +NODE_MODULE(node_os, node::OS::Initialize); diff --git a/src/platform_win32.cc b/src/platform_win32.cc index 3e7029e294b..9ceeeeb9255 100644 --- a/src/platform_win32.cc +++ b/src/platform_win32.cc @@ -2,7 +2,9 @@ #include "platform.h" #include "platform_win32.h" -#include // for MAXPATHLEN +#include + +#include #include // for MAXPATHLEN #include // getpagesize #include @@ -11,6 +13,8 @@ namespace node { +using namespace v8; + static char buf[MAXPATHLEN + 1]; static char *process_title = NULL; @@ -33,12 +37,12 @@ void winapi_perror(const char* prefix = NULL) { } -char** OS::SetupArgs(int argc, char *argv[]) { +char** Platform::SetupArgs(int argc, char *argv[]) { return argv; } -void OS::SetProcessTitle(char *title) { +void Platform::SetProcessTitle(char *title) { // We need to convert _title_ to UTF-16 first, because that's what windows uses internally. // It would be more efficient to use the UTF-16 value that we can obtain from v8, // but it's not accessible from here. @@ -142,7 +146,7 @@ static inline char* _getProcessTitle() { } -const char* OS::GetProcessTitle(int *len) { +const char* Platform::GetProcessTitle(int *len) { // If the process_title was never read before nor explicitly set, // we must query it with getConsoleTitleW if (!process_title) { @@ -159,17 +163,39 @@ const char* OS::GetProcessTitle(int *len) { } -int OS::GetMemory(size_t *rss, size_t *vsize) { - // Not implemented +int Platform::GetMemory(size_t *rss, size_t *vsize) { *rss = 0; *vsize = 0; return 0; } -int OS::GetExecutablePath(char* buffer, size_t* size) { +double Platform::GetFreeMemory() { + return -1; +} + +double Platform::GetTotalMemory() { + return -1; +} + + +int Platform::GetExecutablePath(char* buffer, size_t* size) { *size = 0; return -1; } + +int Platform::GetCPUInfo(Local *cpus) { + return -1; +} + + +double Platform::GetUptime() { + return -1; +} + +int Platform::GetLoadAvg(Local *loads) { + return -1; +} + } // namespace node