pipex/bonus/pipex_utils2.c
Etienne Rey-bethbeder 8a8c75660b Fini Bonus
2023-02-24 14:10:02 +01:00

55 lines
1.5 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipex_utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 15:46:08 by erey-bet #+# #+# */
/* Updated: 2023/02/14 15:48:06 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
int pipex_loop(int argc, int **fk, t_data data)
{
int i;
i = -1;
while (++i < argc - 3)
{
(*fk)[i] = fork();
if ((*fk)[i] < 0)
return (1);
if ((*fk)[i] == 0)
{
if (i == 0 && data.fd1 > 0 && data.cmds[0])
cmd(data, i, 0);
else if (i + 1 < argc - 3)
cmd(data, i, 1);
else
cmd(data, i, 2);
}
}
return (0);
}
int verification_command(char *argv[], t_data data)
{
int i;
i = -1;
while (++i < data.argc - 3)
{
data.cmds[i] = find_command(data.env, data.cmds[i]);
if (data.cmds[i] == NULL)
{
print_error(1, argv[2 + i]);
if (i == data.argc - 4)
return (free_all(&data));
}
}
return (0);
}