| Index: base/environment.cc
|
| diff --git a/base/environment.cc b/base/environment.cc
|
| index 245051d0c1840688552d1fa453356be8e20cc236..ab77cddc0408e1d2d65cdd3581ea0ed592c941f1 100644
|
| --- a/base/environment.cc
|
| +++ b/base/environment.cc
|
| @@ -4,18 +4,13 @@
|
|
|
| #include "base/environment.h"
|
|
|
| +#include <stdlib.h>
|
| #include <vector>
|
|
|
| #include "base/strings/string_piece.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
|
|
| -#if defined(OS_POSIX)
|
| -#include <stdlib.h>
|
| -#elif defined(OS_WIN)
|
| -#include <windows.h>
|
| -#endif
|
| -
|
| namespace base {
|
|
|
| namespace {
|
| @@ -60,42 +55,19 @@ class EnvironmentImpl : public Environment {
|
| if (result)
|
| *result = env_value;
|
| return true;
|
| -#elif defined(OS_WIN)
|
| - DWORD value_length = ::GetEnvironmentVariable(
|
| - UTF8ToWide(variable_name).c_str(), NULL, 0);
|
| - if (value_length == 0)
|
| - return false;
|
| - if (result) {
|
| - scoped_ptr<wchar_t[]> value(new wchar_t[value_length]);
|
| - ::GetEnvironmentVariable(UTF8ToWide(variable_name).c_str(), value.get(),
|
| - value_length);
|
| - *result = WideToUTF8(value.get());
|
| - }
|
| - return true;
|
| #else
|
| #error need to port
|
| #endif
|
| }
|
|
|
| bool SetVarImpl(const char* variable_name, const std::string& new_value) {
|
| -#if defined(OS_POSIX)
|
| // On success, zero is returned.
|
| return !setenv(variable_name, new_value.c_str(), 1);
|
| -#elif defined(OS_WIN)
|
| - // On success, a nonzero value is returned.
|
| - return !!SetEnvironmentVariable(UTF8ToWide(variable_name).c_str(),
|
| - UTF8ToWide(new_value).c_str());
|
| -#endif
|
| }
|
|
|
| bool UnSetVarImpl(const char* variable_name) {
|
| -#if defined(OS_POSIX)
|
| // On success, zero is returned.
|
| return !unsetenv(variable_name);
|
| -#elif defined(OS_WIN)
|
| - // On success, a nonzero value is returned.
|
| - return !!SetEnvironmentVariable(UTF8ToWide(variable_name).c_str(), NULL);
|
| -#endif
|
| }
|
| };
|
|
|
| @@ -139,48 +111,6 @@ bool Environment::HasVar(const char* variable_name) {
|
| return GetVar(variable_name, NULL);
|
| }
|
|
|
| -#if defined(OS_WIN)
|
| -
|
| -string16 AlterEnvironment(const wchar_t* env,
|
| - const EnvironmentMap& changes) {
|
| - string16 result;
|
| -
|
| - // First copy all unmodified values to the output.
|
| - size_t cur_env = 0;
|
| - string16 key;
|
| - while (env[cur_env]) {
|
| - const wchar_t* line = &env[cur_env];
|
| - size_t line_length = ParseEnvLine(line, &key);
|
| -
|
| - // Keep only values not specified in the change vector.
|
| - EnvironmentMap::const_iterator found_change = changes.find(key);
|
| - if (found_change == changes.end())
|
| - result.append(line, line_length);
|
| -
|
| - cur_env += line_length;
|
| - }
|
| -
|
| - // Now append all modified and new values.
|
| - for (EnvironmentMap::const_iterator i = changes.begin();
|
| - i != changes.end(); ++i) {
|
| - if (!i->second.empty()) {
|
| - result.append(i->first);
|
| - result.push_back('=');
|
| - result.append(i->second);
|
| - result.push_back(0);
|
| - }
|
| - }
|
| -
|
| - // An additional null marks the end of the list. We always need a double-null
|
| - // in case nothing was added above.
|
| - if (result.empty())
|
| - result.push_back(0);
|
| - result.push_back(0);
|
| - return result;
|
| -}
|
| -
|
| -#elif defined(OS_POSIX)
|
| -
|
| scoped_ptr<char*[]> AlterEnvironment(const char* const* const env,
|
| const EnvironmentMap& changes) {
|
| std::string value_storage; // Holds concatenated null-terminated strings.
|
| @@ -231,6 +161,4 @@ scoped_ptr<char*[]> AlterEnvironment(const char* const* const env,
|
| return result.Pass();
|
| }
|
|
|
| -#endif // OS_POSIX
|
| -
|
| } // namespace base
|
|
|