From e6b06bc6c5393b31f3b45dbcd0deeb95271fc8b8 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 10 Aug 2011 17:14:23 -0700 Subject: [PATCH] win: fix test-process-env Remove support for setting process.env.TZ as it doesn't seem we can do it x-platform without fixing V8. --- Makefile | 1 + src/node.cc | 25 +++++++++++++++++++++++-- test/simple/test-process-env.js | 11 +++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2f46ae96d1..bab8f8b2c9 100644 --- a/Makefile +++ b/Makefile @@ -177,6 +177,7 @@ UVTEST += simple/test-module-load-list UVTEST += simple/test-path UVTEST += simple/test-pipe-stream UVTEST += simple/test-pipe-file-to-http +UVTEST += simple/test-process-env UVTEST += simple/test-pump-file2tcp UVTEST += simple/test-pump-file2tcp-noexist UVTEST += simple/test-punycode diff --git a/src/node.cc b/src/node.cc index 49d617f381..7f6859bd16 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2002,13 +2002,23 @@ static Handle EnvGetterWarn(Local property, static Handle EnvSetter(Local property, Local value, const AccessorInfo& info) { + HandleScope scope; String::Utf8Value key(property); String::Utf8Value val(value); + #ifdef __POSIX__ setenv(*key, *val, 1); #else // __WIN32__ - NO_IMPL_MSG(setenv) + int n = key.length() + val.length() + 2; + char* pair = new char[n]; + snprintf(pair, n, "%s=%s", *key, *val); + int r = _putenv(pair); + if (r) { + fprintf(stderr, "error putenv: '%s'\n", pair); + } + delete [] pair; #endif + return value; } @@ -2026,15 +2036,26 @@ static Handle EnvQuery(Local property, static Handle EnvDeleter(Local property, const AccessorInfo& info) { + HandleScope scope; + String::Utf8Value key(property); + if (getenv(*key)) { #ifdef __POSIX__ unsetenv(*key); // prototyped as `void unsetenv(const char*)` on some platforms #else - NO_IMPL_MSG(unsetenv) + int n = key.length() + 2; + char* pair = new char[n]; + snprintf(pair, n, "%s=", *key); + int r = _putenv(pair); + if (r) { + fprintf(stderr, "error unsetenv: '%s'\n", pair); + } + delete [] pair; #endif return True(); } + return False(); } diff --git a/test/simple/test-process-env.js b/test/simple/test-process-env.js index 725962d34b..0001fb3e20 100644 --- a/test/simple/test-process-env.js +++ b/test/simple/test-process-env.js @@ -25,10 +25,21 @@ process.env.TZ = 'Europe/Amsterdam'; assert = require('assert'); spawn = require('child_process').spawn; +/* For the moment we are not going to support setting the timezone via the + * environment variables. The problem is that various V8 platform backends + * deal with timezone in different ways. The windows platform backend caches + * the timezone value while the Linux one hits libc for every query. + +https://github.com/joyent/node/blob/08782931205bc4f6d28102ebc29fd806e8ccdf1f/deps/v8/src/platform-linux.cc#L339-345 +https://github.com/joyent/node/blob/08782931205bc4f6d28102ebc29fd806e8ccdf1f/deps/v8/src/platform-win32.cc#L590-596 + + // time difference between Greenwich and Amsterdam is +2 hours in the summer date = new Date('Fri, 10 Sep 1982 03:15:00 GMT'); assert.equal(3, date.getUTCHours()); assert.equal(5, date.getHours()); +*/ + // changes in environment should be visible to child processes if (process.argv[2] == 'you-are-the-child') {