Skip to content

Commit

Permalink
process: EnvGetter to use libuv
Browse files Browse the repository at this point in the history
  • Loading branch information
refack committed Nov 18, 2017
1 parent 707cd3f commit 2968191
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2752,28 +2752,12 @@ static void EnvGetter(Local<Name> property,
if (property->IsSymbol()) {
return info.GetReturnValue().SetUndefined();
}
#ifdef __POSIX__
node::Utf8Value key(isolate, property);
const char* val = getenv(*key);
if (val) {
return info.GetReturnValue().Set(String::NewFromUtf8(isolate, val));
}
#else // _WIN32
node::TwoByteValue key(isolate, property);
WCHAR buffer[32767]; // The maximum size allowed for environment variables.
DWORD result = GetEnvironmentVariableW(reinterpret_cast<WCHAR*>(*key),
buffer,
arraysize(buffer));
// If result >= sizeof buffer the buffer was too small. That should never
// happen. If result == 0 and result != ERROR_SUCCESS the variable was not
// not found.
if ((result > 0 || GetLastError() == ERROR_SUCCESS) &&
result < arraysize(buffer)) {
const uint16_t* two_byte_buffer = reinterpret_cast<const uint16_t*>(buffer);
Local<String> rc = String::NewFromTwoByte(isolate, two_byte_buffer);
return info.GetReturnValue().Set(rc);
char buffer[32767];
int ret = uv_os_getenv(*key, buffer, arraysize(buffer));
if (!ret) {
return info.GetReturnValue().Set(String::NewFromUtf8(isolate, buffer));
}
#endif
}


Expand Down Expand Up @@ -2809,8 +2793,8 @@ static void EnvQuery(Local<Name> property,
#else // _WIN32
node::TwoByteValue key(info.GetIsolate(), property);
WCHAR* key_ptr = reinterpret_cast<WCHAR*>(*key);
if (GetEnvironmentVariableW(key_ptr, nullptr, 0) > 0 ||
GetLastError() == ERROR_SUCCESS) {
GetEnvironmentVariableW(key_ptr, nullptr, 0);
if (GetLastError() != ERROR_ENVVAR_NOT_FOUND) {
rc = 0;
if (key_ptr[0] == L'=') {
// Environment variables that start with '=' are hidden and read-only.
Expand Down

0 comments on commit 2968191

Please sign in to comment.