ajout d'un indicateur pour ne pas fermer le file descripto du fichier, mauvaise idee il faut le rouvrir je pense

This commit is contained in:
hugogogo
2021-10-20 00:15:50 +02:00
parent 4d812cd346
commit f2c8898fcc
4 changed files with 14 additions and 10 deletions

View File

@@ -23,20 +23,21 @@ void **cmd_path(char **argv, char **envp)
return (NULL);
}
int handle_fd(char **input, int i, int fdin, int *fd_in, int *fd_out)
int handle_fd(char **input, int i, int fdin, t_cmd *cmd)
{
int *pipes_fd;
int next_in;
char *tmp;
*fd_in = fdin;
*fd_out = 1;
cmd->fd_in = fdin;
cmd->fd_out = 1;
cmd->fd_redirect = 1;
next_in = 0;
if (input[i + 1])
{
pipes_fd = calloc(2, sizeof(int));
pipe(pipes_fd);
*fd_out = pipes_fd[1];
cmd->fd_out = pipes_fd[1];
next_in = pipes_fd[0];
}
tmp = ft_strchr(input[i], '>');
@@ -44,8 +45,9 @@ int handle_fd(char **input, int i, int fdin, int *fd_in, int *fd_out)
{
tmp[0] = '\0';
tmp = ft_strtrim(tmp + 2, " "); // +2 for "> "
*fd_out = open(tmp, O_WRONLY | O_TRUNC);
next_in = *fd_out;
cmd->fd_out = open(tmp, O_WRONLY | O_TRUNC);
next_in = cmd->fd_out;
cmd->fd_redirect = cmd->fd_out;
}
return (next_in);
}
@@ -65,7 +67,7 @@ t_list *parser(char *input, char **envp)
while (input_split[i])
{
element = calloc(1, sizeof(t_cmd));
tmp_fd = handle_fd(input_split, i, tmp_fd, &(element->fd_in), &(element->fd_out));
tmp_fd = handle_fd(input_split, i, tmp_fd, element);
element->argv = ft_split(input_split[i], ' ');
element->builtin = cmd_path(element->argv, envp);
ft_lstadd_back(&cmd, ft_lstnew(element));