summaryrefslogtreecommitdiffstats
path: root/src/ft_e_lcom.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-23 15:20:42 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-23 15:20:42 +0200
commite3eab8d0d505023977e59940737a7ca42e098a08 (patch)
tree9c9bb39e35e3deb4990015b22ca65ae7b9004b8a /src/ft_e_lcom.c
parentThe worst is that it actually works (diff)
download42-minishell-e3eab8d0d505023977e59940737a7ca42e098a08.tar.gz
42-minishell-e3eab8d0d505023977e59940737a7ca42e098a08.tar.bz2
42-minishell-e3eab8d0d505023977e59940737a7ca42e098a08.tar.xz
42-minishell-e3eab8d0d505023977e59940737a7ca42e098a08.tar.zst
42-minishell-e3eab8d0d505023977e59940737a7ca42e098a08.zip
Ok it's fine
Diffstat (limited to '')
-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);