mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-05-11 15:08:47 +02:00
「🏗️」 wip(heredoc): working on the heredoc...
This commit is contained in:
51
src/exec/heredoc.c
Normal file
51
src/exec/heredoc.c
Normal file
@ -0,0 +1,51 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* heredoc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/20 09:19:39 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/05/20 11:07:21 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int ft_heredoc(char *delimiter)
|
||||
{
|
||||
int fork_pid;
|
||||
int tmp_fd;
|
||||
int status;
|
||||
char *line;
|
||||
|
||||
tmp_fd = open("/tmp/.minishell-heredoc", O_RDWR | O_CREAT, 0644);
|
||||
if (tmp_fd == -1)
|
||||
return (-1);
|
||||
fork_pid = fork();
|
||||
if (fork_pid == -1)
|
||||
{
|
||||
close(tmp_fd);
|
||||
return (-1);
|
||||
}
|
||||
if (!fork_pid)
|
||||
{
|
||||
line = readline("heredoc> ");
|
||||
while (ft_strcmp(line, delimiter))
|
||||
{
|
||||
status = write(tmp_fd, line, ft_strlen(line));
|
||||
status = write(tmp_fd, "\n", 1);
|
||||
free(line);
|
||||
line = readline("heredoc> ");
|
||||
}
|
||||
status = write(tmp_fd, "\0", 1);
|
||||
if (status == -1)
|
||||
{
|
||||
close(tmp_fd);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
else
|
||||
waitpid(fork_pid, NULL, 0);
|
||||
return (tmp_fd);
|
||||
}
|
Reference in New Issue
Block a user