From 09a5cbb9273027b90acf96c61ff939ad5857147b Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 20 Mar 2017 16:28:15 +0100 Subject: [PATCH] =?UTF-8?q?rectif=20gestion=20fichier/dossier=20execut?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 42sh/libft/src/ft_printf/ft_printf.c | 2 +- 42sh/libft/src/mem/ft_memdel.c | 2 +- 42sh/src/exec/pfree_cmd.c | 2 +- 42sh/src/exec/plaunch_file.c | 4 ++-- 42sh/src/exec/pset_cmd.c | 12 +++--------- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/42sh/libft/src/ft_printf/ft_printf.c b/42sh/libft/src/ft_printf/ft_printf.c index 608cee96..e89f0aae 100644 --- a/42sh/libft/src/ft_printf/ft_printf.c +++ b/42sh/libft/src/ft_printf/ft_printf.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ -/* Updated: 2017/03/20 16:10:35 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:13:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/mem/ft_memdel.c b/42sh/libft/src/mem/ft_memdel.c index 52e6508b..59a18066 100644 --- a/42sh/libft/src/mem/ft_memdel.c +++ b/42sh/libft/src/mem/ft_memdel.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:33 by jhalford #+# #+# */ -/* Updated: 2016/11/16 12:23:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:19:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pfree_cmd.c b/42sh/src/exec/pfree_cmd.c index 9715ef1a..96b27702 100644 --- a/42sh/src/exec/pfree_cmd.c +++ b/42sh/src/exec/pfree_cmd.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:58:02 by wescande #+# #+# */ -/* Updated: 2017/03/13 22:31:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:23:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_file.c b/42sh/src/exec/plaunch_file.c index 0ec58d4d..8d629575 100644 --- a/42sh/src/exec/plaunch_file.c +++ b/42sh/src/exec/plaunch_file.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */ -/* Updated: 2017/03/17 20:22:38 by wescande ### ########.fr */ +/* Updated: 2017/03/20 16:26:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ int plaunch_file(t_process *p) { if (!p->data.cmd.path) error_launch("command not found: ", p->data.cmd.av[0], 127); - else if (!p->data.cmd.stat) + else if (access(p->data.cmd.path, F_OK) == -1) error_launch(p->data.cmd.av[0], ": no such file or directory", 127); else if (S_ISDIR(p->data.cmd.stat->st_mode)) error_launch(p->data.cmd.av[0], ": is a directory", 126); diff --git a/42sh/src/exec/pset_cmd.c b/42sh/src/exec/pset_cmd.c index 2c8806ca..eba06520 100644 --- a/42sh/src/exec/pset_cmd.c +++ b/42sh/src/exec/pset_cmd.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 12:41:54 by jhalford #+# #+# */ -/* Updated: 2017/03/20 15:39:40 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:28:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,19 +28,13 @@ int pset_cmd(t_process *p, t_btree *ast) p->type = PROCESS_BUILTIN; else if ((p->type = PROCESS_FILE)) { - DG(); p->data.cmd.stat = ft_memalloc(sizeof(struct stat)); p->data.cmd.execf = &execve; p->data.cmd.path = ft_strchr(p->data.cmd.av[0], '/') ? ft_strdup(p->data.cmd.av[0]) : ft_hash(p->data.cmd.av[0]); - if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) - { - ft_memdel((void**)&p->data.cmd.stat); - ft_dprintf(2, "{red}%s: %s: unexpected stat (2) failure\n", - SHELL_NAME, p->data.cmd.path); + if (p->data.cmd.path && !access(p->data.cmd.path, F_OK) + && stat(p->data.cmd.path, p->data.cmd.stat) == -1) return (-1); - } } - DG(); return (0); }