42_minishell/cmd.c
2023-03-08 18:19:10 +01:00

58 lines
1.7 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
/* Updated: 2023/02/21 22:27:28 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftx/libftx.h"
#include "minishell.h"
#include <sys/wait.h>
void ft_cmddel(void *ptr)
{
t_cmd *content;
content = (t_cmd *) ptr;
if (content->args != NULL)
ft_freer_tab_ultimate(1, content->args);
if (content->executable != NULL)
free(content->executable);
if (content->fd_in > 2)
close(content->fd_in);
if (content->fd_out > 2)
close(content->fd_out);
free(content);
}
int ft_cmd_filler(t_data *data, t_list *element, char **args)
{
t_cmd *content;
char *temp;
size_t i;
if (args == NULL)
return (1);
content = (t_cmd *)element->content;
i = 0;
while (args[i] != NULL)
{
temp = ft_env_filler(data, args[i]);
if (temp == NULL)
return (1);
free(args[i]);
args[i] = temp;
ft_quote_remover(temp);
i++;
}
content->args = args;
content->executable = args[0];
content->pid = -1;
return (0);
}