1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
7 #ifndef SANDBOXING_COMMON_ENVIRONMENTMAP_H_
8 #define SANDBOXING_COMMON_ENVIRONMENTMAP_H_
18 typedef std::wstring NativeEnvironmentString
;
19 typedef std::map
<NativeEnvironmentString
, NativeEnvironmentString
>
22 # define ENVIRONMENT_LITERAL(x) L##x
23 # define ENVIRONMENT_STRING(x) \
24 ((std::wstring)(NS_ConvertUTF8toUTF16((x)).get()))
26 // Returns a modified environment vector constructed from the given environment
27 // and the list of changes given in |changes|. Each key in the environment is
28 // matched against the first element of the pairs. In the event of a match, the
29 // value is replaced by the second of the pair, unless the second is empty, in
30 // which case the key-value is removed.
32 // This Windows version takes and returns a Windows-style environment block
33 // which is a concatenated list of null-terminated 16-bit strings. The end is
34 // marked by a double-null terminator. The size of the returned string will
35 // include the terminators.
36 NativeEnvironmentString
AlterEnvironment(const wchar_t* env
,
37 const EnvironmentMap
& changes
);
41 typedef std::string NativeEnvironmentString
;
42 typedef std::map
<NativeEnvironmentString
, NativeEnvironmentString
>
45 # define ENVIRONMENT_LITERAL(x) x
46 # define ENVIRONMENT_STRING(x) x
48 // See general comments for the Windows version above.
50 // This Posix version takes and returns a Posix-style environment block, which
51 // is a null-terminated list of pointers to null-terminated strings. The
52 // returned array will have appended to it the storage for the array itself so
53 // there is only one pointer to manage, but this means that you can't copy the
54 // array without keeping the original around.
55 std::unique_ptr
<char*[]> AlterEnvironment(const char* const* env
,
56 const EnvironmentMap
& changes
);
62 #endif // SANDBOXING_COMMON_ENVIRONMENTMAP_H_