]> git.dkaiser.de - 42/minishell.git/commitdiff
Outsource error function
authorDominik Kaiser <dkaiser@3-H-6.42heilbronn.de>
Wed, 15 Jan 2025 15:36:45 +0000 (16:36 +0100)
committerDominik Kaiser <dkaiser@3-H-6.42heilbronn.de>
Wed, 15 Jan 2025 15:36:45 +0000 (16:36 +0100)
Makefile
include/minishell.h
src/error.c [new file with mode: 0644]
src/get_cmd_path.c

index 049422de65b7932d461cf1f25f641f498deffa82..415d92476773045df325a147af4c4a94fc7b70d6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,7 @@ SRC     := main.c debug_tools.c init.c signal_handling.c repl.c new_token.c \
            free_token.c new_node.c free_node.c tokenizer.c parser.c \
            parse_cmd.c collect_redirs.c print_ast.c interpreter.c env.c \
            get_cmd_path.c env_to_strlst.c execute_cmd.c format_string.c \
-                  builtins_part_one.c builtins_part_two.c env_tools.c \
+                  builtins_part_one.c builtins_part_two.c env_tools.c error.c \
 
 OBJ_DIR := _obj
 OBJ     := $(addprefix $(OBJ_DIR)/, $(SRC:%.c=%.o))
index 505b21b99b30c7dffa463689c63b173557209f91..88b22d53bca564a5732732d5a5d0214b5ae8f0fd 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/06/22 17:14:49 by dkaiser           #+#    #+#             */
-/*   Updated: 2025/01/15 14:04:19 by dkaiser          ###   ########.fr       */
+/*   Updated: 2025/01/15 16:35:40 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -44,5 +44,6 @@ int                           execute_cmd(t_cmd *cmd, t_env **env);
 char                   *format_string(char *str, t_env *env);
 int set_return_code(int return_code, t_env **env);
 int                            handle_redirections(t_redirection *redirs);
+void   *error(int err_code, char *err_text, int exit_code, int *ret_code);
 
 #endif
diff --git a/src/error.c b/src/error.c
new file mode 100644 (file)
index 0000000..628200d
--- /dev/null
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   error.c                                            :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2025/01/15 16:35:53 by dkaiser           #+#    #+#             */
+/*   Updated: 2025/01/15 16:36:18 by dkaiser          ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "minishell.h"
+#include <errno.h>
+
+void   *error(int err_code, char *err_text, int exit_code, int *ret_code)
+{
+       errno = err_code;
+       perror(err_text);
+       if (ret_code != NULL)
+               *ret_code = exit_code;
+       return (NULL);
+}
index fb457304eefa6ccce9d9754876f0de5379a49894..11100bc953b0da0e31cb1a86c674dd79125fe791 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/12/17 19:19:59 by chuhlig           #+#    #+#             */
-/*   Updated: 2025/01/15 16:32:30 by dkaiser          ###   ########.fr       */
+/*   Updated: 2025/01/15 16:34:56 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -21,7 +21,7 @@
 static char    *get_simple_cmd_path(char *cmd, int *return_code);
 static char    *get_absolute_cmd_path(char *cmd, t_env *env, int *return_code);
 static char    *find_in_path(char *cmd, t_env *env, int *return_code);
-static char    *error(int err_code, char *err_text, int exit_code, int *ret_code);
+static void    *error(int err_code, char *err_text, int exit_code, int *ret_code);
 char           **get_split_path(t_env *env);
 static int     is_directory(char *path);
 
@@ -111,7 +111,7 @@ static char *get_simple_cmd_path(char *cmd, int *return_code)
        return (result);
 }
 
-static char    *error(int err_code, char *err_text, int exit_code, int *ret_code)
+static void    *error(int err_code, char *err_text, int exit_code, int *ret_code)
 {
        errno = err_code;
        perror(err_text);