summaryrefslogtreecommitdiffstats
path: root/src/p_redirs_heredoc.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-27 20:59:02 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-27 20:59:02 +0200
commitcc3aa4907949a66187d0a91b1f7cb55b5cdb21b3 (patch)
tree5f4712c4aa495d97ed1c64b1f828f48febba9c31 /src/p_redirs_heredoc.c
parentProgress (diff)
download42-minishell-cc3aa4907949a66187d0a91b1f7cb55b5cdb21b3.tar.gz
42-minishell-cc3aa4907949a66187d0a91b1f7cb55b5cdb21b3.tar.bz2
42-minishell-cc3aa4907949a66187d0a91b1f7cb55b5cdb21b3.tar.xz
42-minishell-cc3aa4907949a66187d0a91b1f7cb55b5cdb21b3.tar.zst
42-minishell-cc3aa4907949a66187d0a91b1f7cb55b5cdb21b3.zip
In progress
Diffstat (limited to '')
-rw-r--r--src/p_redirs_heredoc.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/p_redirs_heredoc.c b/src/p_redirs_heredoc.c
new file mode 100644
index 0000000..03d044b
--- /dev/null
+++ b/src/p_redirs_heredoc.c
@@ -0,0 +1,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);
+}