environment_internal.h 2.2 KB

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