Chromium Code Reviews

Side by Side Diff: base/environment.cc

Issue 2836088: base: rename Environment::SetEnv to Environment::SetVar. (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « base/environment.h ('k') | base/environment_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/environment.h" 5 #include "base/environment.h"
6 6
7 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #elif defined(OS_WIN) 9 #elif defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
(...skipping 22 matching lines...)
33 std::string alternate_case_var; 33 std::string alternate_case_var;
34 if (first_char >= 'a' && first_char <= 'z') 34 if (first_char >= 'a' && first_char <= 'z')
35 alternate_case_var = StringToUpperASCII(std::string(variable_name)); 35 alternate_case_var = StringToUpperASCII(std::string(variable_name));
36 else if (first_char >= 'A' && first_char <= 'Z') 36 else if (first_char >= 'A' && first_char <= 'Z')
37 alternate_case_var = StringToLowerASCII(std::string(variable_name)); 37 alternate_case_var = StringToLowerASCII(std::string(variable_name));
38 else 38 else
39 return false; 39 return false;
40 return GetEnvImpl(alternate_case_var.c_str(), result); 40 return GetEnvImpl(alternate_case_var.c_str(), result);
41 } 41 }
42 42
43 virtual bool SetEnv(const char* variable_name, const std::string& new_value) { 43 virtual bool SetVar(const char* variable_name, const std::string& new_value) {
44 return SetEnvImpl(variable_name, new_value); 44 return SetVarImpl(variable_name, new_value);
45 } 45 }
46 46
47 virtual bool UnSetVar(const char* variable_name) { 47 virtual bool UnSetVar(const char* variable_name) {
48 return UnSetVarImpl(variable_name); 48 return UnSetVarImpl(variable_name);
49 } 49 }
50 50
51 private: 51 private:
52 bool GetEnvImpl(const char* variable_name, std::string* result) { 52 bool GetEnvImpl(const char* variable_name, std::string* result) {
53 #if defined(OS_POSIX) 53 #if defined(OS_POSIX)
54 const char* env_value = getenv(variable_name); 54 const char* env_value = getenv(variable_name);
(...skipping 13 matching lines...)
68 ::GetEnvironmentVariable(UTF8ToWide(variable_name).c_str(), value.get(), 68 ::GetEnvironmentVariable(UTF8ToWide(variable_name).c_str(), value.get(),
69 value_length); 69 value_length);
70 *result = WideToUTF8(value.get()); 70 *result = WideToUTF8(value.get());
71 } 71 }
72 return true; 72 return true;
73 #else 73 #else
74 #error need to port 74 #error need to port
75 #endif 75 #endif
76 } 76 }
77 77
78 bool SetEnvImpl(const char* variable_name, const std::string& new_value) { 78 bool SetVarImpl(const char* variable_name, const std::string& new_value) {
79 #if defined(OS_POSIX) 79 #if defined(OS_POSIX)
80 // On success, zero is returned. 80 // On success, zero is returned.
81 return setenv(variable_name, new_value.c_str(), 1) == 0; 81 return setenv(variable_name, new_value.c_str(), 1) == 0;
82 #elif defined(OS_WIN) 82 #elif defined(OS_WIN)
83 // On success, a nonzero is returned. 83 // On success, a nonzero is returned.
84 return ::SetEnvironmentVariable(ASCIIToWide(variable_name).c_str(), 84 return ::SetEnvironmentVariable(ASCIIToWide(variable_name).c_str(),
85 ASCIIToWide(new_value).c_str()) != 0; 85 ASCIIToWide(new_value).c_str()) != 0;
86 #endif 86 #endif
87 } 87 }
88 88
(...skipping 28 matching lines...)
117 // static 117 // static
118 Environment* Environment::Create() { 118 Environment* Environment::Create() {
119 return new EnvironmentImpl(); 119 return new EnvironmentImpl();
120 } 120 }
121 121
122 bool Environment::HasVar(const char* variable_name) { 122 bool Environment::HasVar(const char* variable_name) {
123 return GetEnv(variable_name, NULL); 123 return GetEnv(variable_name, NULL);
124 } 124 }
125 125
126 } // namespace base 126 } // namespace base
OLDNEW
« no previous file with comments | « base/environment.h ('k') | base/environment_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine