/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* heredoc.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cchauvet "); line = get_next_line(*ft_get_heredoc()); if (line == NULL) return (1); line[ft_strlen(line) - 1] = '\0'; if (ft_strcmp(line, stop) == 0) { free(line); return (2); } if (ft_format_and_write(data, line, fds[1])) { ft_closer(fds); free(line); return (1); } free(line); return (0); } int ft_heredoc(t_data *data, char *stop) { int fds[2]; int return_code; if (pipe(fds) == -1) return (-1); *ft_get_heredoc() = dup(0); while (true) { return_code = ft_heredoc2(data, stop, fds); if (return_code == 2) break ; else if (return_code) return (-2); } close(fds[1]); *ft_get_heredoc() = -1; return (fds[0]); }