Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion includes/parsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: apuyane <apuyane@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/30 07:27:45 by mcomin #+# #+# */
/* Updated: 2026/03/20 02:00:51 by apuyane ### ########.fr */
/* Updated: 2026/03/21 22:44:09 by apuyane ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -54,5 +54,6 @@ char **clone_charstar(char **old);
char **add_dir(char *directory, char **old_dir);
int strmatch(char *pattern, char *name);
char *get_matching(char *pattern, char **elements);
char *get_rand_numbers(int n);

#endif
4 changes: 3 additions & 1 deletion libs/libft/ft_isalnum.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: apuyane <apuyane@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/18 20:27:21 by apuyane #+# #+# */
/* Updated: 2026/02/14 08:45:54 by apuyane ### ########.fr */
/* Updated: 2026/03/21 22:51:49 by apuyane ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -28,5 +28,7 @@ bool ft_isalnum_string(char *s)
return (false);
i++;
}
if (i == 0)
return (false);
return (true);
}
10 changes: 3 additions & 7 deletions src/parse/redir_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,12 @@ int redir_3(t_data *data, int i, int cmd_idx)
int redir_4(t_data *data, int i, int cmd_idx)
{
int fd;
int rand_fd;
unsigned int rand_num;
char *num_str;
char *name;

rand_fd = open("/dev/urandom", O_RDONLY);
if (rand_fd < 0)
num_str = get_rand_numbers(8);
if (!num_str)
return (1);
read(rand_fd, &rand_num, sizeof(rand_num));
close(rand_fd);
num_str = ft_itoa(rand_num);
name = ft_strjoin("/tmp/sh-thd-", num_str);
free_single(num_str);
fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0644);
Expand All @@ -95,6 +90,7 @@ int redir_4(t_data *data, int i, int cmd_idx)
data->cmds[cmd_idx].infile = fd;
read_heredoc(data->cmds[cmd_idx].redirs[i].file, data->cmds[cmd_idx]);
data->cmds[cmd_idx].infile = open(name, O_RDONLY);
unlink(name);
free_single(name);
return (0);
}
29 changes: 24 additions & 5 deletions src/utils/heredoc_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,36 @@
/* By: apuyane <apuyane@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/17 00:52:23 by apuyane #+# #+# */
/* Updated: 2026/03/21 05:02:42 by apuyane ### ########.fr */
/* Updated: 2026/03/24 00:57:29 by apuyane ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"
#include "libft.h"
#include "free.h"

char *get_rand_numbers(int n)
{
int rand_fd;
char *rand_num;
int bytes_read;

rand_fd = open("/dev/urandom", O_RDONLY);
if (rand_fd < 0)
return (NULL);
rand_num = ft_calloc(n + 1, sizeof(char));
while (1)
{
bytes_read = read(rand_fd, rand_num, n * sizeof(char));
if (bytes_read <= 0)
break ;
if (ft_isalnum_string(rand_num) && ft_strlen(rand_num) == n)
break ;
}
close(rand_fd);
return (rand_num);
}

void read_heredoc(char *delimiter, t_cmd cmd)
{
char *line;
Expand All @@ -30,10 +52,7 @@ void read_heredoc(char *delimiter, t_cmd cmd)
break ;
}
if (g_signal_status == SIGINT)
{
close(cmd.infile);
return ;
}
break ;
if (!ft_strcmp(line, delimiter))
break ;
ft_dprintf(cmd.infile, "%s\n", line);
Expand Down
Loading