blob: 03d044bb9b438e93f2c77e0cc53f6aaf473235ae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* p_redirs_heredoc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
#include "d_define.h"
#include "s_struct.h"
char
*p_get_heredoc(const char path[], t_msh *msh)
{
char *heredoc;
char *line;
int8_t gnl;
heredoc = NULL;
gnl = 1;
if ((heredoc = ft_strdup("")) == NULL)
return (NULL);
while (gnl > 0 && ft_strncmp(path, line, ft_strlen(path) + 1) != 0)
{
gnl = get_next_line(msh->fd, &line);
if ((heredoc = ft_nrealloc(heredoc, ft_strlen(heredoc),
ft_strlen(heredoc) + ft_strlen(line) + 2)) == NULL)
return (heredoc);
ft_strlcpy(heredoc + ft_strlen(heredoc), line, ft_strlen(line) + 1);
heredoc[ft_strlen(heredoc) + 1] = C_NUL;
heredoc[ft_strlen(heredoc)] = C_LF;
}
return (heredoc);
}
|