-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheredoc.c
More file actions
35 lines (32 loc) · 1.31 KB
/
heredoc.c
File metadata and controls
35 lines (32 loc) · 1.31 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* heredoc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jklocker <jklocker@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/30 14:12:03 by jklocker #+# #+# */
/* Updated: 2023/01/30 18:42:56 by jklocker ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void heredoc(t_info *info, int *i, t_node *cur)
{
char *line;
int fd;
char *tmp;
tmp = ft_itoa(*i);
fd = open(tmp, O_CREAT | O_WRONLY | O_TRUNC, 777);
line = readline("> ");
while (ft_strcmp(line, info->cmd_input[*i + 1]) != 0)
{
ft_putendl_fd(line, fd);
line = readline("> ");
}
cur->heredoc = ft_strdup(tmp);
close(fd);
fd = open(tmp, O_CREAT | O_RDONLY, 777);
free(tmp);
cur->in = fd;
*i = *i + 1;
}