-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathutil.cpp
More file actions
33 lines (28 loc) · 1.08 KB
/
Copy pathutil.cpp
File metadata and controls
33 lines (28 loc) · 1.08 KB
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
// global headers
#include <unistd.h>
// local headers
#include "linuxdeploy/subprocess/util.h"
#include "linuxdeploy/util/misc.h"
#ifdef __FreeBSD__
// On FreeBSD environ has to be declared in the consumer code
extern "C" {
extern char** environ;
}
#endif
namespace linuxdeploy::subprocess {
subprocess_env_map_t get_environment() {
subprocess_env_map_t result;
// first, copy existing environment
// we cannot reserve space in the vector unfortunately, as we don't know the size of environ before the iteration
if (environ != nullptr) {
for (auto** current_env_var = environ; *current_env_var != nullptr; ++current_env_var) {
std::string current_env_var_str(*current_env_var);
const auto first_eq = current_env_var_str.find_first_of('=');
const auto env_var_name = current_env_var_str.substr(0, first_eq);
const auto env_var_value = current_env_var_str.substr(first_eq + 1);
result[env_var_name] = env_var_value;
}
}
return result;
}
}