mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-05-11 15:08:47 +02:00
「✏️」 norm(src/exec/*): normed everything...
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/20 09:19:39 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/05/23 07:18:01 by mmoussou ### ########.fr */
|
||||
/* Updated: 2024/06/05 01:21:06 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
/*
|
||||
# mode
|
||||
0: ouvre un nouveau fichier
|
||||
<fd>: close ce fd
|
||||
1: réouvre le fichier pour la lecture
|
||||
-1: pour signifier qu'il faut decrémenter la static
|
||||
*/
|
||||
int fd_manager(int mode)
|
||||
@ -25,13 +25,10 @@ int fd_manager(int mode)
|
||||
char *path;
|
||||
int fd;
|
||||
|
||||
if (mode > 0)
|
||||
close(mode);
|
||||
if (mode)
|
||||
{
|
||||
if (mode < 0)
|
||||
index--;
|
||||
if (mode < 0)
|
||||
return (0);
|
||||
}
|
||||
path = ft_calloc(sizeof(char), 24 + 3);
|
||||
if (!path)
|
||||
return (-1);
|
||||
@ -41,9 +38,12 @@ int fd_manager(int mode)
|
||||
if (!index_itoa)
|
||||
return (-1);
|
||||
index++;
|
||||
strcat(path, "/tmp/.minishell-heredoc-");
|
||||
strcat(path, index_itoa);
|
||||
fd = open(path, O_RDONLY | O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
||||
ft_strlcat(path, "/tmp/.minishell-heredoc-", 24);
|
||||
ft_strlcat(path, index_itoa, ft_strlen(index_itoa));
|
||||
if (mode > 0)
|
||||
fd = open(path, O_RDONLY);
|
||||
else
|
||||
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
||||
return (fd);
|
||||
}
|
||||
|
||||
@ -52,7 +52,6 @@ static int get_input(char *delimiter, int fd)
|
||||
char *line;
|
||||
int status;
|
||||
|
||||
printf("%s | ", delimiter);
|
||||
line = readline("heredoc> ");
|
||||
while (ft_strcmp(line, delimiter))
|
||||
{
|
||||
@ -73,9 +72,7 @@ static int get_input(char *delimiter, int fd)
|
||||
status = write(fd, "\0", 1);
|
||||
if (status == -1)
|
||||
fd_manager(fd);
|
||||
if (status == -1)
|
||||
return (-1);
|
||||
return (0);
|
||||
return (-(status == -1));
|
||||
}
|
||||
|
||||
int ft_heredoc(char *delimiter)
|
||||
@ -92,7 +89,8 @@ int ft_heredoc(char *delimiter)
|
||||
fork_pid = fork();
|
||||
if (fork_pid == -1)
|
||||
{
|
||||
fd_manager(fd);
|
||||
fd_manager(-1);
|
||||
close(fd);
|
||||
return (-1);
|
||||
}
|
||||
if (!fork_pid)
|
||||
@ -102,5 +100,5 @@ int ft_heredoc(char *delimiter)
|
||||
}
|
||||
else
|
||||
waitpid(fork_pid, NULL, 0);
|
||||
return (fd);
|
||||
return (fd_manager(1));
|
||||
}
|
||||
|
Reference in New Issue
Block a user