41 lines
1.4 KiB
C
41 lines
1.4 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* :::::::: */
|
|
/* builtin_export.c :+: :+: */
|
|
/* +:+ */
|
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
|
/* +#+ */
|
|
/* Created: 2025/02/20 11:32:53 by whaffman #+# #+# */
|
|
/* Updated: 2025/03/03 14:37:13 by whaffman ######## odam.nl */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "minishell.h"
|
|
|
|
int builtin_export(t_minishell *msh, t_command *cmd)
|
|
{
|
|
t_environment *env;
|
|
char **arr;
|
|
int i;
|
|
|
|
i = 0;
|
|
arr = NULL;
|
|
while (cmd->args[++i] != NULL)
|
|
{
|
|
arr = ft_split_safe(msh, cmd->args[i], '=');
|
|
if (arr[1] == NULL)
|
|
return (FAILURE) ;
|
|
env = environment_get(msh, arr[0]);
|
|
if (env != NULL)
|
|
{
|
|
free_safe(msh, (void **)&(env->value));
|
|
env->value = ft_strdup_safe(msh, arr[1]);
|
|
}
|
|
else
|
|
environment_add(msh, arr[0], arr[1]);
|
|
ft_free_arr_safe(msh, arr);
|
|
}
|
|
ft_free_arr_safe(msh, arr);
|
|
return (SUCCESS);
|
|
}
|