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.
 
 

43 lines
1.6 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipexargs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hroussea <hroussea@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/06/08 19:34:23 by hroussea #+# #+# */
/* Updated: 2021/06/09 13:25:47 by hroussea ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "pipex/pipex.h"
#include "pipex/fileutils.h"
#include <libft/string.h>
static void get_path_info(t_ppipex ppxi, char **envp)
{
while (envp)
{
if (ft_strncmp(*envp, "PATH=", 5) == 0)
{
ppxi->path = ft_split((*envp + 5), ':');
break ;
}
++envp;
}
}
_Bool pipex_parse(t_ppipex ppxi, int argc, char **argv, char **envp)
{
if (argc != 5)
return (write(1, "usage: pipex <file1> <cmd1> <cmd2> <file2>\n", 44));
get_path_info(ppxi, envp);
ppxi->cmd1.fd = open_file(argv[1], O_RDONLY, 0);
ppxi->cmd2.fd = open_file(argv[4], O_RDWR | O_CREAT | O_TRUNC, 0b110100100);
if (ppxi->cmd1.fd < 0 || ppxi->cmd2.fd < 0)
return (1);
ppxi->cmd1.command = ft_split(argv[2], ' ');
ppxi->cmd2.command = ft_split(argv[3], ' ');
return (0);
}