summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-28 17:14:39 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-28 17:14:39 +0200
commit60865a986bfbee6923c8b85351d1ec6f5062bc08 (patch)
treef6bbfd6bcde2826b30f09a101fb98d59e5d09708
parentlater (diff)
download42-minishell-60865a986bfbee6923c8b85351d1ec6f5062bc08.tar.gz
42-minishell-60865a986bfbee6923c8b85351d1ec6f5062bc08.tar.bz2
42-minishell-60865a986bfbee6923c8b85351d1ec6f5062bc08.tar.xz
42-minishell-60865a986bfbee6923c8b85351d1ec6f5062bc08.tar.zst
42-minishell-60865a986bfbee6923c8b85351d1ec6f5062bc08.zip
In progress
Diffstat (limited to '')
-rw-r--r--src/e_redirs.c19
-rw-r--r--src/p_redirs_heredoc.c11
2 files changed, 24 insertions, 6 deletions
diff --git a/src/e_redirs.c b/src/e_redirs.c
index 7416349..b07026f 100644
--- a/src/e_redirs.c
+++ b/src/e_redirs.c
@@ -15,12 +15,25 @@
#include <stddef.h>
#include <fcntl.h>
#include <unistd.h>
+#include <stdio.h>
#include "f_fail.h"
#include "s_destroy.h"
#include "s_line.h"
#include "s_struct.h"
+static void e_redir_minus_two(struct s_lredir *ptr, t_msh *msh)
+{
+ (void)msh;
+ if (ptr->heredoc == NULL)
+ {
+ return ;
+ }
+ dup2(STDOUT_FILENO, STDIN_FILENO);
+ write(STDOUT_FILENO, ptr->heredoc, ft_strlen(ptr->heredoc) + 1);
+ close(STDIN_FILENO);
+}
+
static void e_redir_minus_one(struct s_lredir *ptr, t_msh *msh)
{
int32_t fd;
@@ -67,7 +80,11 @@ void e_dup_redirs(const t_com *com, t_msh *msh)
ptr = com->rdr;
while (ptr != NULL)
{
- if (ptr->redir == -1)
+ if (ptr->redir == -2)
+ {
+ e_redir_minus_two(ptr, msh);
+ }
+ else if (ptr->redir == -1)
{
e_redir_minus_one(ptr, msh);
}
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 <libft.h>
+#include <stdint.h>
#include <unistd.h>
#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);
}