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