blob: ff5eaeb8545231b0429b83960eb17d650244576c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include "env.h"
#include <util/system/platform.h>
#ifdef _darwin_
#include <crt_externs.h>
#define environ (*_NSGetEnviron())
#endif
#ifdef _linux_
#include <unistd.h>
#endif
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
#if defined(_linux_) || defined(_darwin_)
std::vector<std::string> GetEnvironNameValuePairs()
{
std::vector<std::string> result;
for (char** envIt = environ; *envIt; ++envIt) {
result.emplace_back(*envIt);
}
return result;
}
#endif
std::pair<TStringBuf, std::optional<TStringBuf>> ParseEnvironNameValuePair(TStringBuf pair)
{
if (auto pos = pair.find('='); pos != std::string::npos) {
return {pair.substr(0, pos), pair.substr(pos + 1)};
} else {
return {pair, std::nullopt};
}
}
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT::NThreading
|