diff options
author | Rudy Bousset <rbousset@z2r5p6.le-101.fr> | 2019-10-30 20:58:53 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r5p6.le-101.fr> | 2019-10-30 20:58:53 +0100 |
commit | 82b2fa3b5d726c99dbed0c2717f8ab9c415ac5f8 (patch) | |
tree | 50eabf3f9c3975d2a3ff204fd48cdfeab3cef861 | |
parent | work work (diff) | |
download | 42-minishell-82b2fa3b5d726c99dbed0c2717f8ab9c415ac5f8.tar.gz 42-minishell-82b2fa3b5d726c99dbed0c2717f8ab9c415ac5f8.tar.bz2 42-minishell-82b2fa3b5d726c99dbed0c2717f8ab9c415ac5f8.tar.xz 42-minishell-82b2fa3b5d726c99dbed0c2717f8ab9c415ac5f8.tar.zst 42-minishell-82b2fa3b5d726c99dbed0c2717f8ab9c415ac5f8.zip |
changes
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | inc/minishell.h | 1 | ||||
-rw-r--r-- | src/ft_exec.c | 1 | ||||
-rw-r--r-- | src/ft_history.c | 28 | ||||
-rw-r--r-- | src/main.c | 1 |
5 files changed, 26 insertions, 6 deletions
@@ -20,6 +20,7 @@ SRCS = \ ${SRCS_DIR}ft_echo.c \ ${SRCS_DIR}ft_pwd.c \ ${SRCS_DIR}ft_exec.c \ + ${SRCS_DIR}ft_history.c \ OBJS_DIR = obj/ OBJS = $(patsubst ${SRCS_DIR}%.c,${OBJS_DIR}%.o,${SRCS}) diff --git a/inc/minishell.h b/inc/minishell.h index bbb4c2c..e3fb5b6 100644 --- a/inc/minishell.h +++ b/inc/minishell.h @@ -11,5 +11,6 @@ int ft_pwd(void); uint8_t ft_exit(char **com); int ft_error(const char *com, int errno); int ft_exec(char **app); +int ft_history(char *arg); #endif diff --git a/src/ft_exec.c b/src/ft_exec.c index 31fcaf2..b9d50cf 100644 --- a/src/ft_exec.c +++ b/src/ft_exec.c @@ -11,5 +11,4 @@ ft_exec(char **app) while (app[i]) i++; return (execve(app[0] + 2, app, NULL)); - return (0); } diff --git a/src/ft_history.c b/src/ft_history.c index fa28100..6a82a16 100644 --- a/src/ft_history.c +++ b/src/ft_history.c @@ -1,17 +1,35 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_history.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/30 20:36:05 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/30 20:36:07 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + #include <libft.h> #include <minishell.h> +#include <stdlib.h> +#include <stdio.h> #include <fcntl.h> #include <unistd.h> int -ft_history(const char *arg) +ft_history(char *arg) { + char c; int fd; - int ret; + int r; - if ((fd = open("joe-sh_history", O_RDWR | O_CREAT)) == -1) + if ((fd = open("joe-sh_history", O_CREAT | O_RDWR, 0644)) == -1) return (1); - ret = write(1, arg + "\n", ft_strlen(arg) + 1); + while ((r = read(fd, &c, 1)) != EOF) + puts(&c); + ft_putendl_fd(arg, fd); close(fd); - return (ret); + return (0); } @@ -47,6 +47,7 @@ int i++; } arg[i] = '\0'; + ft_history(arg); ret = ft_process_arg(arg); } free(arg); |