42_minishell/builtin/export.c

41 lines
1.4 KiB
C
Raw Permalink Normal View History

2023-02-14 11:11:39 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* export.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 14:27:08 by cchauvet #+# #+# */
/* Updated: 2023/02/14 14:52:50 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../minishell.h"
int main(char **env)
{
t_list **env_lst;
t_list *current;
char *key;
char *value;
env_lst = init_env(env);
current = *env_lst;
while (current != NULL)
{
value = ft_strchr(current->content, '=') + 1;
key = ft_strndup(current->content,
ft_strlen(current->content) - ft_strlen(value));
if (key == NULL)
{
ft_lstclear(env_lst, env_del);
return (1);
}
ft_printf("declare -x %s=\"%s\"\n", key, value);
free(key);
current = current->next;
}
ft_lstclear(env_lst, env_del);
return (0);
}