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