You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

75 lines
1.9 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipexlife.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hroussea <hroussea@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/06/08 16:28:02 by hroussea #+# #+# */
/* Updated: 2021/06/09 13:31:00 by hroussea ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "pipex/pipex.h"
t_ppipex pipex_init(t_ppipex ppxi)
{
ppxi->path = 0;
ppxi->cmd1.command = 0;
ppxi->cmd1.fd = -1;
ppxi->cmd2.command = 0;
ppxi->cmd2.fd = -1;
return (ppxi);
}
t_ppipex pipex_spawn(void)
{
t_ppipex ppxi;
ppxi = malloc(sizeof(struct s_pipex));
return (pipex_init(ppxi));
}
static void free_path(t_ppipex ppxi)
{
int i;
i = 0;
while (ppxi->path && ppxi->path[i])
free(ppxi->path[i++]);
free(ppxi->path);
ppxi->path = 0;
}
t_ppipex pipex_deinit(t_ppipex ppxi)
{
int i;
i = 0;
free_path(ppxi);
while (ppxi->cmd1.command && ppxi->cmd1.command[i])
free(ppxi->cmd1.command[i++]);
free(ppxi->cmd1.command);
ppxi->cmd1.command = 0;
i = 0;
while (ppxi->cmd2.command && ppxi->cmd2.command[i])
free(ppxi->cmd2.command[i++]);
free(ppxi->cmd2.command);
ppxi->cmd2.command = 0;
if (ppxi->cmd1.fd > 0)
{
close(ppxi->cmd1.fd);
ppxi->cmd1.fd = -1;
}
if (ppxi->cmd2.fd > 0)
{
close(ppxi->cmd2.fd);
ppxi->cmd2.fd = -1;
}
return (ppxi);
}
void pipex_despawn(t_ppipex ppxi)
{
free(pipex_deinit(ppxi));
}