1 //===-- Environment.cpp -----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Utility/Environment.h"
12 using namespace lldb_private;
14 char *Environment::Envp::make_entry(llvm::StringRef Key,
15 llvm::StringRef Value) {
16 const size_t size = Key.size() + 1 /*=*/ + Value.size() + 1 /*\0*/;
17 char *Result = reinterpret_cast<char *>(
18 Allocator.Allocate(sizeof(char) * size, alignof(char)));
21 Next = std::copy(Key.begin(), Key.end(), Next);
23 Next = std::copy(Value.begin(), Value.end(), Next);
29 Environment::Envp::Envp(const Environment &Env) {
30 Data = reinterpret_cast<char **>(
31 Allocator.Allocate(sizeof(char *) * (Env.size() + 1), alignof(char *)));
33 for (const auto &KV : Env)
34 *Next++ = make_entry(KV.first(), KV.second);
38 Environment::Environment(const char *const *Env) {
45 void Environment::insert(const_iterator first, const_iterator last) {
46 while (first != last) {
47 try_emplace(first->first(), first->second);