Merge branch 'master' of https://github.com/jzck/minishell
This commit is contained in:
commit
9a5c35ff4b
1 changed files with 12 additions and 3 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/14 11:27:03 by gwojda #+# #+# */
|
/* Created: 2017/02/14 11:27:03 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/04 15:52:19 by gwojda ### ########.fr */
|
/* Updated: 2017/03/10 12:10:03 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,17 +15,26 @@
|
||||||
void ft_add_in_history_file(char *str)
|
void ft_add_in_history_file(char *str)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
int i;
|
||||||
char *home;
|
char *home;
|
||||||
char *path;
|
char *path;
|
||||||
|
char **hist;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
hist = ft_strsplit(str, '\n');
|
||||||
if (!(home = ft_getenv(data_singleton()->env, "HOME")))
|
if (!(home = ft_getenv(data_singleton()->env, "HOME")))
|
||||||
return ;
|
return ;
|
||||||
path = ft_str3join(home, "/", ".42sh_history");
|
path = ft_str3join(home, "/", ".42sh_history");
|
||||||
fd = open(path, O_CREAT | O_WRONLY | O_APPEND, S_IWUSR | S_IRUSR);
|
fd = open(path, O_CREAT | O_WRONLY | O_APPEND, S_IWUSR | S_IRUSR);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return ;
|
return ;
|
||||||
write(fd, str, ft_strlen(str));
|
while (hist[i])
|
||||||
write(fd, "\n", 1);
|
{
|
||||||
|
write(fd, hist[i], ft_strlen(str));
|
||||||
|
write(fd, "\n", 1);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
ft_sstrfree(hist);
|
||||||
free(path);
|
free(path);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue