rectif lorsque get_next_line renvoi une erreur + modif des fd pour pas bug quand on reset
This commit is contained in:
parent
c6a23fb2ac
commit
d8e76dba3d
2 changed files with 13 additions and 9 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/15 14:19:48 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 readline(int fd, int prompt, char **input)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
|
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);
|
readline_init(prompt);
|
||||||
*input = ft_read_stdin();
|
*input = ft_read_stdin();
|
||||||
if (STR)
|
if (STR)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/06 18:40:58 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)
|
else if (data->opts & SH_OPTS_LC)
|
||||||
{
|
{
|
||||||
pipe(fds);
|
pipe(fds);
|
||||||
fd = fds[PIPE_READ];
|
dup2_close(fds[PIPE_READ], 10);
|
||||||
|
fd = 10;
|
||||||
|
//fd = fds[PIPE_READ];
|
||||||
file = *cliopts_getdata(av);
|
file = *cliopts_getdata(av);
|
||||||
write(fds[PIPE_WRITE], file, ft_strlen(file));
|
write(fds[PIPE_WRITE], file, ft_strlen(file));
|
||||||
close(fds[PIPE_WRITE]);
|
close(fds[PIPE_WRITE]);
|
||||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||||
return (fd);
|
return (fd);
|
||||||
}
|
}
|
||||||
else if ((file = *cliopts_getdata(av)))
|
else if ((file = *cliopts_getdata(av)) && !stat(file, &buf))
|
||||||
{
|
{
|
||||||
stat(file, &buf);
|
|
||||||
fd = -1;
|
fd = -1;
|
||||||
if (S_ISDIR(buf.st_mode))
|
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)
|
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);
|
ft_printf("{red}%s: %s: No such file or directory\n{eoc}", av[0], file);
|
||||||
return (fd);
|
if (fd > 0 && !dup2_close(fd, 10) && (fd = 10))
|
||||||
|
return (fd);
|
||||||
}
|
}
|
||||||
return (STDIN);
|
return (STDIN);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue