1*6777b538SAndroid Build Coastguard Worker // Copyright 2019 The Chromium Authors 2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file. 4*6777b538SAndroid Build Coastguard Worker 5*6777b538SAndroid Build Coastguard Worker // This file contains internal routines that are called by other files in 6*6777b538SAndroid Build Coastguard Worker // base/process/. 7*6777b538SAndroid Build Coastguard Worker 8*6777b538SAndroid Build Coastguard Worker #ifndef BASE_PROCESS_ENVIRONMENT_INTERNAL_H_ 9*6777b538SAndroid Build Coastguard Worker #define BASE_PROCESS_ENVIRONMENT_INTERNAL_H_ 10*6777b538SAndroid Build Coastguard Worker 11*6777b538SAndroid Build Coastguard Worker #include <memory> 12*6777b538SAndroid Build Coastguard Worker 13*6777b538SAndroid Build Coastguard Worker #include "base/base_export.h" 14*6777b538SAndroid Build Coastguard Worker #include "base/environment.h" 15*6777b538SAndroid Build Coastguard Worker #include "build/build_config.h" 16*6777b538SAndroid Build Coastguard Worker 17*6777b538SAndroid Build Coastguard Worker namespace base { 18*6777b538SAndroid Build Coastguard Worker namespace internal { 19*6777b538SAndroid Build Coastguard Worker 20*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) 21*6777b538SAndroid Build Coastguard Worker // Returns a modified environment vector constructed from the given environment 22*6777b538SAndroid Build Coastguard Worker // and the list of changes given in |changes|. Each key in the environment is 23*6777b538SAndroid Build Coastguard Worker // matched against the first element of the pairs. In the event of a match, the 24*6777b538SAndroid Build Coastguard Worker // value is replaced by the second of the pair, unless the second is empty, in 25*6777b538SAndroid Build Coastguard Worker // which case the key-value is removed. 26*6777b538SAndroid Build Coastguard Worker // 27*6777b538SAndroid Build Coastguard Worker // This POSIX version takes and returns a POSIX-style environment block, which 28*6777b538SAndroid Build Coastguard Worker // is a null-terminated list of pointers to null-terminated strings. The 29*6777b538SAndroid Build Coastguard Worker // returned array will have appended to it the storage for the array itself so 30*6777b538SAndroid Build Coastguard Worker // there is only one pointer to manage, but this means that you can't copy the 31*6777b538SAndroid Build Coastguard Worker // array without keeping the original around. 32*6777b538SAndroid Build Coastguard Worker BASE_EXPORT std::unique_ptr<char*[]> AlterEnvironment( 33*6777b538SAndroid Build Coastguard Worker const char* const* env, 34*6777b538SAndroid Build Coastguard Worker const EnvironmentMap& changes); 35*6777b538SAndroid Build Coastguard Worker #elif BUILDFLAG(IS_WIN) 36*6777b538SAndroid Build Coastguard Worker // Returns a modified environment vector constructed from the given environment 37*6777b538SAndroid Build Coastguard Worker // and the list of changes given in |changes|. Each key in the environment is 38*6777b538SAndroid Build Coastguard Worker // matched against the first element of the pairs. In the event of a match, the 39*6777b538SAndroid Build Coastguard Worker // value is replaced by the second of the pair, unless the second is empty, in 40*6777b538SAndroid Build Coastguard Worker // which case the key-value is removed. 41*6777b538SAndroid Build Coastguard Worker // 42*6777b538SAndroid Build Coastguard Worker // This Windows version takes and returns a Windows-style environment block, 43*6777b538SAndroid Build Coastguard Worker // which is a string containing several null-terminated strings followed by an 44*6777b538SAndroid Build Coastguard Worker // extra terminating null character. So, e.g., the environment A=1 B=2 is 45*6777b538SAndroid Build Coastguard Worker // represented as L"A=1\0B=2\0\0". 46*6777b538SAndroid Build Coastguard Worker BASE_EXPORT NativeEnvironmentString 47*6777b538SAndroid Build Coastguard Worker AlterEnvironment(const wchar_t* env, const EnvironmentMap& changes); 48*6777b538SAndroid Build Coastguard Worker #endif // OS_* 49*6777b538SAndroid Build Coastguard Worker 50*6777b538SAndroid Build Coastguard Worker } // namespace internal 51*6777b538SAndroid Build Coastguard Worker } // namespace base 52*6777b538SAndroid Build Coastguard Worker 53*6777b538SAndroid Build Coastguard Worker #endif // BASE_PROCESS_ENVIRONMENT_INTERNAL_H_ 54