23 using namespace folly;
27 std::unordered_map<std::string, std::string>
data;
28 for (
auto it =
environ; it && *it; ++it) {
31 auto equalsPosition = entry.
find(
'=');
32 if (equalsPosition == entry.
npos) {
34 "Environment contains an non key-value-pair string \"", entry,
"\"")};
38 if (data.count(key)) {
40 "Environment contains duplicate value for \"", key,
"\"")};
49 for (
const auto& kvp :
env_) {
50 PCHECK(0 == setenv(kvp.first.c_str(), kvp.second.c_str(), (int)
true));
55 std::vector<std::string> result;
56 for (
auto const& pair :
env_) {
57 result.emplace_back(to<std::string>(pair.first,
"=", pair.second));
64 size_t totalStringLength{};
65 for (
auto const& pair :
env_) {
66 totalStringLength += pair.first.size() + pair.second.size() +
69 size_t allocationRequired =
70 (totalStringLength /
sizeof(
char*) + 1) + env_.size() + 1;
71 char** raw =
new char*[allocationRequired];
73 char* stringBase =
reinterpret_cast<char*
>(&raw[env_.size() + 1]);
74 char*
const stringEnd =
reinterpret_cast<char*
>(&raw[allocationRequired]);
75 for (
auto const& pair : env_) {
78 *ptrBase = stringBase;
79 size_t lengthIncludingNullTerminator = key.size() + 1 + value.size() + 1;
80 CHECK_GT(stringEnd - lengthIncludingNullTerminator, stringBase);
81 memcpy(stringBase, key.c_str(), key.size());
82 stringBase += key.size();
84 memcpy(stringBase, value.c_str(), value.size() + 1);
85 stringBase += value.size() + 1;
89 CHECK_EQ(env_.size(), ptrBase - raw);
90 return {raw, [](
char**
ptr) {
delete[]
ptr; }};
constexpr detail::Map< Move > move
size_type find(const_range_type str) const
—— Concurrent Priority Queue Implementation ——
std::vector< std::string > toVector() const
static EnvironmentState fromCurrentEnvironment()
constexpr auto data(C &c) -> decltype(c.data())
Range subpiece(size_type first, size_type length=npos) const
std::unique_ptr< char *, void(*)(char **)> toPointerArray() const
std::string toString() const
static const size_type npos
void setAsCurrentEnvironment()
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)