1 //===-- Environment.cpp -----------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Utility/Environment.h"
11 using namespace lldb_private;
13 char *Environment::Envp::make_entry(llvm::StringRef Key,
14 llvm::StringRef Value) {
15 const size_t size = Key.size() + 1 /*=*/ + Value.size() + 1 /*\0*/;
16 char *Result = reinterpret_cast<char *>(
17 Allocator.Allocate(sizeof(char) * size, alignof(char)));
20 Next = std::copy(Key.begin(), Key.end(), Next);
22 Next = std::copy(Value.begin(), Value.end(), Next);
28 Environment::Envp::Envp(const Environment &Env) {
29 Data = reinterpret_cast<char **>(
30 Allocator.Allocate(sizeof(char *) * (Env.size() + 1), alignof(char *)));
32 for (const auto &KV : Env)
33 *Next++ = make_entry(KV.first(), KV.second);
37 Environment::Environment(const char *const *Env) {
44 void Environment::insert(const_iterator first, const_iterator last) {
45 while (first != last) {
46 try_emplace(first->first(), first->second);