minishell/src/prompt/ft_load_history.c
2025-02-05 17:14:12 +01:00

35 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_load_history.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 16:44:51 by whaffman #+# #+# */
/* Updated: 2025/02/05 17:11:59 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_load_history(void)
{
int fd;
char *line;
fd = open(".minishell_history", O_RDONLY);
if (fd < 0)
return ;
while (TRUE)
{
line = get_next_line(fd);
if (!line)
return ;
line[ft_strlen(line) - 1] = '\0';
if (*line)
add_history(line);
free(line);
}
close(fd);
}