rectif lorsque get_next_line renvoi une erreur + modif des fd pour pas bug quand on reset

This commit is contained in:
wescande 2017-03-14 23:09:31 +01:00
parent c6a23fb2ac
commit d8e76dba3d
2 changed files with 13 additions and 9 deletions

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}