OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // Note that the variable may be defined but empty. | 59 // Note that the variable may be defined but empty. |
60 if (result) | 60 if (result) |
61 *result = env_value; | 61 *result = env_value; |
62 return true; | 62 return true; |
63 #elif defined(OS_WIN) | 63 #elif defined(OS_WIN) |
64 DWORD value_length = ::GetEnvironmentVariable( | 64 DWORD value_length = ::GetEnvironmentVariable( |
65 UTF8ToWide(variable_name).c_str(), NULL, 0); | 65 UTF8ToWide(variable_name).c_str(), NULL, 0); |
66 if (value_length == 0) | 66 if (value_length == 0) |
67 return false; | 67 return false; |
68 if (result) { | 68 if (result) { |
69 scoped_array<wchar_t> value(new wchar_t[value_length]); | 69 scoped_ptr<wchar_t[]> value(new wchar_t[value_length]); |
70 ::GetEnvironmentVariable(UTF8ToWide(variable_name).c_str(), value.get(), | 70 ::GetEnvironmentVariable(UTF8ToWide(variable_name).c_str(), value.get(), |
71 value_length); | 71 value_length); |
72 *result = WideToUTF8(value.get()); | 72 *result = WideToUTF8(value.get()); |
73 } | 73 } |
74 return true; | 74 return true; |
75 #else | 75 #else |
76 #error need to port | 76 #error need to port |
77 #endif | 77 #endif |
78 } | 78 } |
79 | 79 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // static | 118 // static |
119 Environment* Environment::Create() { | 119 Environment* Environment::Create() { |
120 return new EnvironmentImpl(); | 120 return new EnvironmentImpl(); |
121 } | 121 } |
122 | 122 |
123 bool Environment::HasVar(const char* variable_name) { | 123 bool Environment::HasVar(const char* variable_name) { |
124 return GetVar(variable_name, NULL); | 124 return GetVar(variable_name, NULL); |
125 } | 125 } |
126 | 126 |
127 } // namespace base | 127 } // namespace base |
OLD | NEW |