42_minishell/heredoc.c

37 lines
1.2 KiB
C
Raw Permalink Normal View History

2023-02-17 10:33:52 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* heredoc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 15:36:26 by cchauvet #+# #+# */
/* Updated: 2023/02/17 16:21:02 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftx/libftx.h"
2023-02-03 10:02:52 -05:00
#include "minishell.h"
int ft_heredoc(char *stop)
{
int fds[2];
char *line;
pipe(fds);
line = readline("> ");
while (line != NULL)
{
if (ft_strcmp(line, stop) == 0)
{
free(line);
break ;
}
2023-02-17 10:33:52 -05:00
ft_putendl_fd(line, fds[1]);
2023-02-03 10:02:52 -05:00
free(line);
line = readline("> ");
}
close(fds[1]);
return (fds[0]);
}