mirror of
https://github.com/neovim/neovim.git
synced 2025-10-03 16:36:30 +00:00
Use dict_T to pass env vars to process spawning code
Co-authored-by: Matthieu Coudron <mattator@gmail.com>
This commit is contained in:
@@ -1523,6 +1523,33 @@ varnumber_T tv_dict_get_number(const dict_T *const d, const char *const key)
|
||||
return tv_get_number(&di->di_tv);
|
||||
}
|
||||
|
||||
/// Converts a dict to an environment
|
||||
///
|
||||
///
|
||||
char **tv_dict_to_env(dict_T *denv)
|
||||
{
|
||||
size_t env_size = (size_t)tv_dict_len(denv);
|
||||
|
||||
size_t i = 0;
|
||||
char **env = NULL;
|
||||
|
||||
// + 1 for NULL
|
||||
env = xmalloc((env_size + 1) * sizeof(*env));
|
||||
|
||||
TV_DICT_ITER(denv, var, {
|
||||
const char *str = tv_get_string(&var->di_tv);
|
||||
assert(str);
|
||||
size_t len = STRLEN(var->di_key) + strlen(str) + strlen("=") + 1;
|
||||
env[i] = xmalloc(len);
|
||||
snprintf(env[i], len, "%s=%s", (char *)var->di_key, str);
|
||||
i++;
|
||||
});
|
||||
|
||||
// must be null terminated
|
||||
env[env_size] = NULL;
|
||||
return env;
|
||||
}
|
||||
|
||||
/// Get a string item from a dictionary
|
||||
///
|
||||
/// @param[in] d Dictionary to get item from.
|
||||
|
Reference in New Issue
Block a user