ipc/glue/EnvironmentMap.h
author Andreea Pavel <apavel@mozilla.com>
Tue, 27 Nov 2018 08:53:18 +0200
changeset 507399 b0e69b1368832a3846c0940a6fb8bb834bdc62a1
parent 507385 8fa5e81ad8015f9bd5ba2b7497f840e4cc50b8bd
child 508163 6f3709b3878117466168c40affa7bca0b60cf75b
permissions -rw-r--r--
Backed out 8 changesets (bug 1446161, bug 1487287, bug 1488993, bug 1474991, bug 1496608) for very frequent automation.py crashes on a CLOSED TREE Backed out changeset 8b1f88d7bfeb (bug 1487287) Backed out changeset 8fa5e81ad801 (bug 1487287) Backed out changeset 7a480161fa0f (bug 1474991) Backed out changeset 80116391b7fe (bug 1446161) Backed out changeset 1bdf64b29121 (bug 1446161) Backed out changeset 37bf52f0e9cf (bug 1446161) Backed out changeset 8ede2ebe6b7a (bug 1496608) Backed out changeset cea43bc88c7a (bug 1488993)

// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SANDBOXING_COMMON_ENVIRONMENTMAP_H_
#define SANDBOXING_COMMON_ENVIRONMENTMAP_H_

#include <map>
#include <memory>
#include <string>

namespace base {

#if defined(OS_WIN)

typedef std::wstring NativeEnvironmentString;
typedef std::map<NativeEnvironmentString, NativeEnvironmentString>
    EnvironmentMap;

#define ENVIRONMENT_LITERAL(x) L##x
#define ENVIRONMENT_STRING(x) (std::wstring)(NS_ConvertUTF8toUTF16((x)).get())

// Returns a modified environment vector constructed from the given environment
// and the list of changes given in |changes|. Each key in the environment is
// matched against the first element of the pairs. In the event of a match, the
// value is replaced by the second of the pair, unless the second is empty, in
// which case the key-value is removed.
//
// This Windows version takes and returns a Windows-style environment block
// which is a concatenated list of null-terminated 16-bit strings. The end is
// marked by a double-null terminator. The size of the returned string will
// include the terminators.
NativeEnvironmentString AlterEnvironment(const wchar_t* env,
                                         const EnvironmentMap& changes);

#elif defined(OS_POSIX)

typedef std::string NativeEnvironmentString;
typedef std::map<NativeEnvironmentString, NativeEnvironmentString>
    EnvironmentMap;

#define ENVIRONMENT_LITERAL(x) x
#define ENVIRONMENT_STRING(x) ((x)).get()

// See general comments for the Windows version above.
//
// This Posix version takes and returns a Posix-style environment block, which
// is a null-terminated list of pointers to null-terminated strings. The
// returned array will have appended to it the storage for the array itself so
// there is only one pointer to manage, but this means that you can't copy the
// array without keeping the original around.
std::unique_ptr<char* []> AlterEnvironment(
    const char* const* env,
    const EnvironmentMap& changes);

#endif

}  // namespace base

#endif  // SANDBOXING_COMMON_ENVIRONMENTMAP_H_