@@ -56,16 +56,11 @@ typedef int mode_t;
5656#include < errno.h>
5757#include < sys/types.h>
5858
59- #if defined(__MINGW32__) || defined(_MSC_VER)
60- # include < platform_win32.h> /* winapi_perror() */
61- #endif
62-
6359#ifdef __POSIX__
6460# include < pwd.h> /* getpwnam() */
6561# include < grp.h> /* getgrnam() */
6662#endif
6763
68- #include " platform.h"
6964#include < node_buffer.h>
7065#ifdef __POSIX__
7166# include < node_io_watcher.h>
@@ -137,7 +132,7 @@ extern char **environ;
137132#define module_load_list NODE_VAR (module_load_list)
138133#define node_isolate NODE_VAR (node_isolate)
139134#define debugger_running NODE_VAR (debugger_running)
140-
135+ # define prog_start_time NODE_VAR (prog_start_time)
141136
142137namespace node {
143138
@@ -854,6 +849,30 @@ Local<Value> UVException(int errorno,
854849
855850
856851#ifdef _WIN32
852+ // Does about the same as strerror(),
853+ // but supports all windows error messages
854+ static const char *winapi_strerror (const int errorno) {
855+ char *errmsg = NULL ;
856+
857+ FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
858+ FORMAT_MESSAGE_IGNORE_INSERTS, NULL , errorno,
859+ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errmsg, 0 , NULL );
860+
861+ if (errmsg) {
862+ // Remove trailing newlines
863+ for (int i = strlen (errmsg) - 1 ;
864+ i >= 0 && (errmsg[i] == ' \n ' || errmsg[i] == ' \r ' ); i--) {
865+ errmsg[i] = ' \0 ' ;
866+ }
867+
868+ return errmsg;
869+ } else {
870+ // FormatMessage failed
871+ return " Unknown error" ;
872+ }
873+ }
874+
875+
857876Local<Value> WinapiErrnoException (int errorno,
858877 const char * syscall,
859878 const char * msg,
@@ -1485,17 +1504,19 @@ static void CheckStatus(uv_timer_t* watcher, int status) {
14851504 }
14861505}
14871506
1507+
14881508static Handle<Value> Uptime (const Arguments& args) {
14891509 HandleScope scope;
14901510 assert (args.Length () == 0 );
1511+ double uptime;
14911512
1492- double uptime = Platform::GetUptime ( true );
1513+ uv_err_t err = uv_uptime (&uptime );
14931514
1494- if (uptime < 0 ) {
1515+ if (err. code != UV_OK ) {
14951516 return Undefined ();
14961517 }
14971518
1498- return scope.Close (Number::New (uptime));
1519+ return scope.Close (Number::New (uptime - prog_start_time ));
14991520}
15001521
15011522
@@ -1537,10 +1558,10 @@ v8::Handle<v8::Value> MemoryUsage(const v8::Arguments& args) {
15371558
15381559 size_t rss;
15391560
1540- int r = Platform::GetMemory (&rss);
1561+ uv_err_t err = uv_resident_set_memory (&rss);
15411562
1542- if (r != 0 ) {
1543- return ThrowException (Exception::Error ( String::New ( strerror (errno)) ));
1563+ if (err. code != UV_OK ) {
1564+ return ThrowException (UVException (err. code , " uv_resident_set_memory " ));
15441565 }
15451566
15461567 Local<Object> info = Object::New ();
@@ -1829,9 +1850,9 @@ static Handle<Value> Binding(const Arguments& args) {
18291850static Handle<Value> ProcessTitleGetter (Local<String> property,
18301851 const AccessorInfo& info) {
18311852 HandleScope scope;
1832- int len ;
1833- const char *s = Platform::GetProcessTitle (&len );
1834- return scope.Close (s ? String::New (s, len) : String::Empty ( ));
1853+ char buffer[ 512 ] ;
1854+ uv_get_process_title (buffer, sizeof (buffer) );
1855+ return scope.Close (String::New (buffer ));
18351856}
18361857
18371858
@@ -1840,7 +1861,8 @@ static void ProcessTitleSetter(Local<String> property,
18401861 const AccessorInfo& info) {
18411862 HandleScope scope;
18421863 String::Utf8Value title (value->ToString ());
1843- Platform::SetProcessTitle (*title);
1864+ // TODO: protect with a lock
1865+ uv_set_process_title (*title);
18441866}
18451867
18461868
@@ -2490,8 +2512,11 @@ static Handle<Value> DebugProcess(const Arguments& args) {
24902512
24912513
24922514char ** Init (int argc, char *argv[]) {
2515+ // Initialize prog_start_time to get relative uptime.
2516+ uv_uptime (&prog_start_time);
2517+
24932518 // Hack aroung with the argv pointer. Used for process.title = "blah".
2494- argv = node::Platform::SetupArgs (argc, argv);
2519+ argv = uv_setup_args (argc, argv);
24952520
24962521 // Parse a few arguments which are specific to Node.
24972522 node::ParseArgs (argc, argv);
0 commit comments