open_access fixes
This commit is contained in:
parent
49f160bf49
commit
2873c44c72
3 changed files with 6 additions and 6 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/25 01:10:56 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;
|
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));
|
return (-ERR_SET(E_SYS_NOFILE, file));
|
||||||
if (is_directory(file))
|
if (is_directory(file))
|
||||||
return (-ERR_SET(E_SYS_ISDIR, 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));
|
return (-ERR_SET(E_SYS_NOPERM, file));
|
||||||
if ((fd = open(file, o_flag, o_perm)) < 0)
|
if ((fd = open(file, o_flag, o_perm)) < 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/06 22:03:53 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/06 22:09:53 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;
|
int fdnew;
|
||||||
|
|
||||||
fdnew = redir->n;
|
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)
|
O_RDONLY, 0)) != 0)
|
||||||
return (ft_perror(NULL));
|
return (ft_perror(NULL));
|
||||||
dup2(fdold, fdnew);
|
dup2(fdold, fdnew);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue