From 60865a986bfbee6923c8b85351d1ec6f5062bc08 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 28 Sep 2020 17:14:39 +0200 Subject: In progress --- src/p_redirs_heredoc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/p_redirs_heredoc.c') diff --git a/src/p_redirs_heredoc.c b/src/p_redirs_heredoc.c index fd5b399..6b939fe 100644 --- a/src/p_redirs_heredoc.c +++ b/src/p_redirs_heredoc.c @@ -11,14 +11,14 @@ /* ************************************************************************** */ #include +#include #include #include "d_define.h" #include "m_prompt.h" #include "s_struct.h" -char - *p_get_heredoc(const char path[], t_msh *msh) +char *p_get_heredoc(const char path[], t_msh *msh) { char *heredoc; char *line; @@ -34,9 +34,9 @@ char if (msh->fd == STDIN_FILENO) m_prompt_psx(2, msh); gnl = get_next_line(msh->fd, &line); - if (ft_strncmp(path, line, ft_strlen(path) + 1) != 0) + if (ft_strncmp(path, line, ft_strlen(path) + 1) == 0) break ; - if ((heredoc = ft_nrealloc(heredoc, ft_strlen(heredoc), + if ((heredoc = ft_nrealloc(heredoc, ft_strlen(heredoc) + 1, ft_strlen(heredoc) + ft_strlen(line) + 2)) == NULL) break ; ft_strlcpy(heredoc + ft_strlen(heredoc), line, ft_strlen(line) + 1); @@ -45,6 +45,7 @@ char ft_memdel((void*)&line); } - ft_memdel((void*)&line); + if (gnl > 0) + ft_memdel((void*)&line); return (heredoc); } -- cgit v1.2.3