diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-06 21:56:20 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-06 21:56:20 +0200 |
commit | 4543c3ba3222d47780ad3e091cfe6f3098cc2bca (patch) | |
tree | fb8a70bf05464a6fa2c820cc43ea34421340c903 /src/m_loop.c | |
parent | Commit from minishell (diff) | |
download | 42-minishell-4543c3ba3222d47780ad3e091cfe6f3098cc2bca.tar.gz 42-minishell-4543c3ba3222d47780ad3e091cfe6f3098cc2bca.tar.bz2 42-minishell-4543c3ba3222d47780ad3e091cfe6f3098cc2bca.tar.xz 42-minishell-4543c3ba3222d47780ad3e091cfe6f3098cc2bca.tar.zst 42-minishell-4543c3ba3222d47780ad3e091cfe6f3098cc2bca.zip |
Stacked
Diffstat (limited to 'src/m_loop.c')
-rw-r--r-- | src/m_loop.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/m_loop.c b/src/m_loop.c index 17668a5..d5a3ceb 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -15,7 +15,9 @@ #include <stdlib.h> #include <fcntl.h> #include <unistd.h> +#include <limits.h> +#include "d_define.h" #include "e_line.h" #include "m_loop_next.h" #include "m_prompt.h" @@ -36,18 +38,20 @@ void m_dump_hist(t_msh *msh) { int32_t fd; - char *histfile_path; + char histfile[PATH_MAX]; - if (ft_strlen(msh->hist) > 0 && - (histfile_path = u_get_var_value("$HISTFILE", msh)) != NULL) + if (ft_strlen(msh->hist) > 0) { - if ((fd = open(histfile_path, - O_WRONLY | O_CREAT | O_APPEND, 0644)) != -1) + u_get_var_value(histfile, "$HISTFILE", PATH_MAX, msh); + if (histfile[0] != C_NUL) { - write(fd, msh->hist, ft_strlen(msh->hist)); - close(fd); + if ((fd = open(histfile, + O_WRONLY | O_CREAT | O_APPEND, 0644)) != -1) + { + ft_dprintf(fd, "%s", msh->hist); + close(fd); + } } - ft_memdel((void*)&histfile_path); } } |