diff options
| author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-23 00:28:59 +0200 | 
|---|---|---|
| committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-23 00:28:59 +0200 | 
| commit | 6647c2b82dfe2ffc1efd7dd99590c54ad06d85af (patch) | |
| tree | 67dfec3e56ce1ba21d2c119ac43dfeeadfcc4cbd /src/ft_p_lcom.c | |
| parent | Good (diff) | |
| download | 42-minishell-6647c2b82dfe2ffc1efd7dd99590c54ad06d85af.tar.gz 42-minishell-6647c2b82dfe2ffc1efd7dd99590c54ad06d85af.tar.bz2 42-minishell-6647c2b82dfe2ffc1efd7dd99590c54ad06d85af.tar.xz 42-minishell-6647c2b82dfe2ffc1efd7dd99590c54ad06d85af.tar.zst 42-minishell-6647c2b82dfe2ffc1efd7dd99590c54ad06d85af.zip | |
Now time to pipe(2)
Diffstat (limited to 'src/ft_p_lcom.c')
| -rw-r--r-- | src/ft_p_lcom.c | 32 | 
1 files changed, 29 insertions, 3 deletions
| diff --git a/src/ft_p_lcom.c b/src/ft_p_lcom.c index 5890b0f..aec344f 100644 --- a/src/ft_p_lcom.c +++ b/src/ft_p_lcom.c @@ -13,13 +13,39 @@  #include <libft.h>  #include <stdlib.h>  #include <stdint.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h>  #include "ft_s_lcom.h"  #include "ft_s_struct.h" -void -	ft_check_redir_file() +static void +	ft_check_redir_file(t_lcom **link)  { +	int32_t	fd; +	fd = 0; +	if ((*link)->redir == -1 && (fd = open((*link)->rdrpath, O_RDONLY)) == -1) +	{ +		/* TODO: better error handling | DON'T EXEC CMD | retval 1 */ +		if (errno == ENOENT) +			ft_dprintf(STDERR_FILENO, +				"minishell: %s: No such file or directory\n", (*link)->rdrpath); +		else if (errno == EACCES) +			ft_dprintf(STDERR_FILENO, +				"minishell: %s: Permission denied\n", (*link)->rdrpath); +		return ; +	} +	else if ((*link)->redir == 1 +		&& (fd = open((*link)->rdrpath, O_CREAT | O_WRONLY, 0644)) == -1) +	{ +		/* TODO: same as above */ +		if (errno == EACCES) +			ft_dprintf(STDERR_FILENO, +				"minishell: %s: Permission denied\n", (*link)->rdrpath); +	} +	/* TODO: >> redir file check */ +	close(fd);  }  static void @@ -92,6 +118,7 @@ int8_t  		ft_rdr_err_check(ptr, link);  		if (ft_get_rdrpath(ptr, link) != 0)  			return (-1); +		ft_check_redir_file(link);  	}  	return (0);  } @@ -115,7 +142,6 @@ int8_t  			return (-1);  		}  		ft_lcom_add_back(&msh->curr, link); -		ft_printf("%s\n", msh->curr->rdrpath);  		i++;  	}  	ft_delwords(words); | 
