diff options
Diffstat (limited to '')
| -rw-r--r-- | src/s_lredir.c | 12 | 
1 files changed, 10 insertions, 2 deletions
| diff --git a/src/s_lredir.c b/src/s_lredir.c index b2e94e8..59ed6e1 100644 --- a/src/s_lredir.c +++ b/src/s_lredir.c @@ -13,7 +13,10 @@  #include <libft.h>  #include <stdint.h>  #include <stdlib.h> +#include <string.h> +#include <fcntl.h>  #include <unistd.h> +#include <errno.h>  #ifdef __linux__  # include <linux/limits.h>  #else @@ -66,7 +69,7 @@ void			s_lredir_clear(struct s_lredir **lredir)  	*lredir = NULL;  } -static int32_t		s_get_right_fd(const char path[]) +static int32_t	s_get_right_fd(const char path[])  {  	char	*ptr;  	int32_t	rfd; @@ -79,7 +82,12 @@ static int32_t		s_get_right_fd(const char path[])  		ft_dprintf(STDERR_FILENO, "minishell: %s: ambigous redirect\n", path);  		return (-1);  	} -	rfd = 0; +	rfd = ft_atoi(path); +	if (fcntl(rfd, F_GETFD) == -1) +	{ +		ft_dprintf(STDERR_FILENO, "minishell: %s: %s\n", path, strerror(errno)); +		return (-1); +	}  	return (rfd);  } | 
