Moved find command in path to executor, fixed env save code
This commit is contained in:
@@ -32,26 +32,37 @@ void set_envp(
|
||||
char **envp,
|
||||
t_minishell *msh
|
||||
) {
|
||||
char **splitted_env;
|
||||
char *equal_sign;
|
||||
char *key;
|
||||
char *value;
|
||||
|
||||
if (msh == NULL || envp == NULL)
|
||||
return ;
|
||||
msh->variables.environment
|
||||
= ft_hashmap_new(32, ft_hashmap_hashstr, ft_hashmap_strcmp);
|
||||
if (msh == NULL)
|
||||
{
|
||||
ft_hashmap_clear(&msh->variables.environment, free);
|
||||
if (msh->variables.environment == NULL)
|
||||
return ;
|
||||
}
|
||||
while (*envp != NULL)
|
||||
{
|
||||
splitted_env = ft_split(*envp, '=');
|
||||
if (splitted_env == NULL)
|
||||
equal_sign = ft_strchr(*envp, '=');
|
||||
if (equal_sign == NULL)
|
||||
{
|
||||
key = ft_strdup(*envp);
|
||||
value = ft_strdup("");
|
||||
}
|
||||
else
|
||||
{
|
||||
key = ft_substr(*envp, 0, equal_sign - *envp);
|
||||
value = ft_strdup(equal_sign + 1);
|
||||
}
|
||||
if (key == NULL || value == NULL)
|
||||
{
|
||||
free(key);
|
||||
free(value);
|
||||
ft_hashmap_clear(&msh->variables.environment, free);
|
||||
return ;
|
||||
}
|
||||
ft_hashmap_put(msh->variables.environment,
|
||||
ft_strdup(splitted_env[0]), ft_strdup(splitted_env[1]));
|
||||
ft_free_split(splitted_env);
|
||||
ft_hashmap_put(msh->variables.environment, key, value);
|
||||
envp++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user