From d8e76dba3d2a038f45cdd6d3854eaef5e23f9e83 Mon Sep 17 00:00:00 2001 From: wescande Date: Tue, 14 Mar 2017 23:09:31 +0100 Subject: [PATCH] rectif lorsque get_next_line renvoi une erreur + modif des fd pour pas bug quand on reset --- 42sh/src/line-editing/readline.c | 6 ++++-- 42sh/src/main/main.c | 16 +++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index 17b476d9..c2fabd19 100644 --- a/42sh/src/line-editing/readline.c +++ b/42sh/src/line-editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/03/14 21:34:46 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 22:41:51 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,10 @@ int readline(int fd, int prompt, char **input) { + int ret; + if (!SH_IS_INTERACTIVE(data_singleton()->opts)) - return (get_next_line(fd, input) == 0); + return ((ret = get_next_line(fd, input)) >= 0 ? !ret : ret); readline_init(prompt); *input = ft_read_stdin(); if (STR) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 9140d82b..a41485ca 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/14 21:50:56 by jhalford ### ########.fr */ +/* Updated: 2017/03/14 23:08:20 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -95,22 +95,24 @@ int get_input_fd(char **av) else if (data->opts & SH_OPTS_LC) { pipe(fds); - fd = fds[PIPE_READ]; + dup2_close(fds[PIPE_READ], 10); + fd = 10; + //fd = fds[PIPE_READ]; file = *cliopts_getdata(av); write(fds[PIPE_WRITE], file, ft_strlen(file)); close(fds[PIPE_WRITE]); fcntl(fd, F_SETFD, FD_CLOEXEC); return (fd); } - else if ((file = *cliopts_getdata(av))) + else if ((file = *cliopts_getdata(av)) && !stat(file, &buf)) { - stat(file, &buf); fd = -1; if (S_ISDIR(buf.st_mode)) - ft_printf("{red}%s: %s: is a directory\n{eoc}", g_argv[0], file); + ft_printf("{red}%s: %s: is a directory\n{eoc}", av[0], file); else if ((fd = open(file, O_RDONLY | O_CLOEXEC)) < 0) - ft_printf("{red}%s: %s: No such file or directory\n{eoc}", g_argv[0], file); - return (fd); + ft_printf("{red}%s: %s: No such file or directory\n{eoc}", av[0], file); + if (fd > 0 && !dup2_close(fd, 10) && (fd = 10)) + return (fd); } return (STDIN); }