From 2873c44c726a77c3421f9e7b197c83532df73624 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sat, 25 Mar 2017 02:36:44 +0100 Subject: [PATCH] open_access fixes --- 42sh/libft/src/sys/open_access.c | 6 +++--- 42sh/src/exec/redirect_great.c | 2 +- 42sh/src/exec/redirect_less.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/42sh/libft/src/sys/open_access.c b/42sh/libft/src/sys/open_access.c index f3e7d3eb..0d77b423 100644 --- a/42sh/libft/src/sys/open_access.c +++ b/42sh/libft/src/sys/open_access.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/25 01:10:56 by jhalford #+# #+# */ -/* Updated: 2017/03/25 02:19:58 by jhalford ### ########.fr */ +/* Updated: 2017/03/25 02:26:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,11 +16,11 @@ int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm) { int fd; - if (access(file, F_OK) != 0) + if (a_flag & F_OK && access(file, F_OK) != 0) return (-ERR_SET(E_SYS_NOFILE, file)); if (is_directory(file)) return (-ERR_SET(E_SYS_ISDIR, file)); - if (access(file, a_flag) != 0) + if (access(file, F_OK) == 0 && access(file, a_flag) != 0) return (-ERR_SET(E_SYS_NOPERM, file)); if ((fd = open(file, o_flag, o_perm)) < 0) { diff --git a/42sh/src/exec/redirect_great.c b/42sh/src/exec/redirect_great.c index 20ae5822..d0cc00a9 100644 --- a/42sh/src/exec/redirect_great.c +++ b/42sh/src/exec/redirect_great.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */ -/* Updated: 2017/03/25 01:49:35 by jhalford ### ########.fr */ +/* Updated: 2017/03/25 02:25:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redirect_less.c b/42sh/src/exec/redirect_less.c index d38e079b..bc2cf96f 100644 --- a/42sh/src/exec/redirect_less.c +++ b/42sh/src/exec/redirect_less.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */ -/* Updated: 2017/03/25 01:52:33 by jhalford ### ########.fr */ +/* Updated: 2017/03/25 02:25:58 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ int redirect_less(t_redir *redir) int fdnew; fdnew = redir->n; - if ((fdold = open_access(redir->word, W_OK, + if ((fdold = open_access(redir->word, F_OK | W_OK, O_RDONLY, 0)) != 0) return (ft_perror(NULL)); dup2(fdold, fdnew);