summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-08-15 18:20:23 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-08-15 18:20:23 +0200
commit7df3f33f3c644e53577b53fed433bfe9a4ff0715 (patch)
tree226cb02e6cd877df38bd6fafa5066b643380d71d /src
parentCan read scripts, but need to handle fails (diff)
download42-minishell-7df3f33f3c644e53577b53fed433bfe9a4ff0715.tar.gz
42-minishell-7df3f33f3c644e53577b53fed433bfe9a4ff0715.tar.bz2
42-minishell-7df3f33f3c644e53577b53fed433bfe9a4ff0715.tar.xz
42-minishell-7df3f33f3c644e53577b53fed433bfe9a4ff0715.tar.zst
42-minishell-7df3f33f3c644e53577b53fed433bfe9a4ff0715.zip
Error handling ok
Diffstat (limited to '')
-rw-r--r--src/f_com.c3
-rw-r--r--src/f_fail.h1
-rw-r--r--src/f_file.c31
-rw-r--r--src/f_file.h20
-rw-r--r--src/m_argv.c3
5 files changed, 56 insertions, 2 deletions
diff --git a/src/f_com.c b/src/f_com.c
index 9c4e02a..5ca03eb 100644
--- a/src/f_com.c
+++ b/src/f_com.c
@@ -19,5 +19,6 @@
void
f_fail_command_not_found(const char command[])
{
- ft_dprintf(STDERR_FILENO, "%s: %s: %s\n", "minishell", command, FT_FAIL_COMMAND_NOT_FOUND);
+ ft_dprintf(STDERR_FILENO, "%s: %s: %s\n", "minishell", command,
+ FT_FAIL_COMMAND_NOT_FOUND);
}
diff --git a/src/f_fail.h b/src/f_fail.h
index b1b3b8c..dfb46e3 100644
--- a/src/f_fail.h
+++ b/src/f_fail.h
@@ -17,6 +17,7 @@
#include "f_alloc.h"
#include "f_chdir.h"
#include "f_errno.h"
+#include "f_file.h"
#include "f_redir.h"
#include "f_shlvl.h"
#include "s_struct.h"
diff --git a/src/f_file.c b/src/f_file.c
new file mode 100644
index 0000000..c26596c
--- /dev/null
+++ b/src/f_file.c
@@ -0,0 +1,31 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* f_file.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include "s_destroy.h"
+#include "s_struct.h"
+
+void
+ f_open_file(char filename[],
+ t_msh *msh)
+{
+ ft_dprintf(STDERR_FILENO, "%s: %s: %s\n", msh->shname,
+ filename,
+ strerror(errno));
+ s_destroy(msh);
+ exit(127);
+}
diff --git a/src/f_file.h b/src/f_file.h
new file mode 100644
index 0000000..f34f038
--- /dev/null
+++ b/src/f_file.h
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* f_file.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef F_FILE_H
+#define F_FILE_H
+
+#include "s_struct.h"
+
+void f_open_file(char filename[], t_msh *msh);
+
+#endif
diff --git a/src/m_argv.c b/src/m_argv.c
index 1e23bae..0c32e3b 100644
--- a/src/m_argv.c
+++ b/src/m_argv.c
@@ -15,6 +15,7 @@
#include <fcntl.h>
#include <unistd.h>
+#include "f_fail.h"
#include "d_define.h"
#include "m_comm.h"
#include "m_loop.h"
@@ -44,7 +45,7 @@ uint8_t
else
{
if ((fd = open(*(argv + 1), O_RDONLY)) < 0)
- f_open_file(msh);
+ f_open_file(*(argv + 1), msh);
msh->ret = m_loop(fd, msh);
close(fd);
}