summaryrefslogtreecommitdiffstats
path: root/src/ft_e_lcom.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ft_e_lcom.c')
-rw-r--r--src/ft_e_lcom.c29
1 files changed, 25 insertions, 4 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);