diff options
Diffstat (limited to '')
| -rw-r--r-- | src/ft_e_lcom.c | 29 | ||||
| -rw-r--r-- | src/ft_p_lcom.c | 34 | 
2 files changed, 27 insertions, 36 deletions
diff --git a/src/ft_e_lcom.c b/src/ft_e_lcom.c index af1b88e..51c183a 100644 --- a/src/ft_e_lcom.c +++ b/src/ft_e_lcom.c @@ -17,6 +17,7 @@  #include <unistd.h>  #include <signal.h>  #include <sys/wait.h> +#include <errno.h>  #include "ft_s_destroy.h"  #include "ft_s_lcom.h"  #include "ft_s_struct.h" @@ -56,22 +57,42 @@ uint8_t  			/* TODO: handle exit | bu_id = 6 */  			if ((pid = fork()) == 0)  			{ -				if (ptr->redir == 1) +				if (ptr->redir == -1) +				{ +					if (ptr->redir == -1 && (fd = open(ptr->rdrpath, O_RDONLY)) == -1) +					{ +						if (errno == ENOENT) +							ft_dprintf(STDERR_FILENO, +								"minishell: %s: No such file or directory\n", ptr->rdrpath); +						else if (errno == EACCES) +							ft_dprintf(STDERR_FILENO, +								"minishell: %s: Permission denied\n", ptr->rdrpath); +					} +				} +				else if (ptr->redir == 1)  				{  					if ((fd = open(ptr->rdrpath, -						O_CREAT | O_TRUNC | O_WRONLY, 0644))) +						O_CREAT | O_TRUNC | O_WRONLY, 0644)) == -1)  					{  						/* TODO: handle err with errno */ +						if (errno == EACCES) +							ft_dprintf(STDERR_FILENO, +								"minishell: %s: Permission denied\n", +								ptr->rdrpath);  					}  					dup2(fd, STDOUT_FILENO);  					close(fd);  				} -				if (ptr->redir == 2) +				else if (ptr->redir == 2)  				{  					if ((fd = open(ptr->rdrpath, -						O_CREAT | O_APPEND | O_WRONLY, 0644))) +						O_CREAT | O_APPEND | O_WRONLY, 0644)) == -1)  					{  						/* TODO: handle err with errno */ +						if (errno == EACCES) +							ft_dprintf(STDERR_FILENO, +								"minishell: %s: Permission denied\n", +								ptr->rdrpath);  					}  					dup2(fd, STDOUT_FILENO);  					close(fd); diff --git a/src/ft_p_lcom.c b/src/ft_p_lcom.c index 45fcf17..b5fdc85 100644 --- a/src/ft_p_lcom.c +++ b/src/ft_p_lcom.c @@ -20,35 +20,6 @@  #include "ft_s_struct.h"  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  	ft_rdr_err_check(char *ptr,  				t_lcom **link)  { @@ -59,7 +30,7 @@ static void  	else if ((*link)->redir == 1 && ft_ischarset("<", *(ptr + 1)))  	{  	} -	else if ((*link)->redir == 1 && ft_ischarset("<>", *(ptr + 1))) +	else if ((*link)->redir == 2 && ft_ischarset("<>", *(ptr + 1)))  	{  	}  } @@ -87,6 +58,7 @@ static int8_t  		ptr++;  	}  	*p_rdrpath = '\0'; +	ft_printf("[%s]\n", (*link)->rdrpath);  	return (0);  } @@ -118,8 +90,6 @@ int8_t  		ft_rdr_err_check(ptr, link);  		if (ft_get_rdrpath(ptr, link) != 0)  			return (-1); -		/* TODO: don't check files here, check at run-time */ -		ft_check_redir_file(link);  	}  	return (0);  }  | 
