Port env_init to Rust

- This does not adopt it.
This commit is contained in:
Henrik Hørlück Berg
2023-08-20 15:34:01 +02:00
committed by Fabian Boehm
parent e7f8fb04cc
commit 96e58dac21
7 changed files with 406 additions and 8 deletions

View File

@@ -233,6 +233,25 @@ static std::map<wcstring, wcstring> inheriteds;
const std::map<wcstring, wcstring> &env_get_inherited() { return inheriteds; }
void set_inheriteds_ffi() {
wcstring key, val;
const char *const *envp = environ;
int i = 0;
while (envp && envp[i]) i++;
while (i--) {
const wcstring key_and_val = str2wcstring(envp[i]);
size_t eql = key_and_val.find(L'=');
if (eql == wcstring::npos) {
// PORTING: Should this not be key_and_val?
inheriteds[key] = L"";
} else {
key.assign(key_and_val, 0, eql);
val.assign(key_and_val, eql + 1, wcstring::npos);
inheriteds[key] = val;
}
}
}
void env_init(const struct config_paths_t *paths, bool do_uvars, bool default_paths) {
env_stack_t &vars = env_stack_t::principal();
// Import environment variables. Walk backwards so that the first one out of any duplicates wins

View File

@@ -350,4 +350,6 @@ const std::map<wcstring, wcstring> &env_get_inherited();
/// fish_history_val is the value of the "$fish_history" variable, or "fish" if not set.
wcstring_list_ffi_t get_history_variable_text_ffi(const wcstring &fish_history_val);
void set_inheriteds_ffi();
#endif