]> git.dkaiser.de - 42/minishell.git/commitdiff
Add free to get_cmd_path
authorDominik Kaiser <dkaiser@3-G-5.42heilbronn.de>
Wed, 22 Jan 2025 16:04:26 +0000 (17:04 +0100)
committerDominik Kaiser <dkaiser@3-G-5.42heilbronn.de>
Wed, 22 Jan 2025 16:04:26 +0000 (17:04 +0100)
src/execute_cmd.c
src/get_cmd_path.c
src/new_node.c

index 2179515f3314c2989dec75572ce3a4b32b528a23..811c92cde42dcc87672e582731fe5b6b6f9a697c 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/12/17 19:21:35 by chuhlig           #+#    #+#             */
-/*   Updated: 2025/01/22 16:29:34 by chuhlig          ###   ########.fr       */
+/*   Updated: 2025/01/22 16:53:04 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -27,12 +27,10 @@ int invalid_input(char *cmd)
 
 int    is_builtin(char *cmd)
 {
-       if ((ft_strcmp(cmd, "export") == 0) || (ft_strcmp(cmd, "unset") == 0)
+       return ((ft_strcmp(cmd, "export") == 0) || (ft_strcmp(cmd, "unset") == 0)
                || (ft_strcmp(cmd, "cd") == 0) || (ft_strcmp(cmd, "exit") == 0)
                || (ft_strcmp(cmd, "echo") == 0) || (ft_strcmp(cmd, "pwd") == 0)
-               || (ft_strcmp(cmd, "env") == 0))
-               return (1);
-       return(invalid_input(cmd));
+               || (ft_strcmp(cmd, "env") == 0));
 }
 
 int    execute_builtin(char **args, t_env **env)
index 01f24b1b902f236593ebfcf2fbded520b2594e9f..f882734e7fd92f666a057f3523dbad535f555cfc 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/12/17 19:19:59 by chuhlig           #+#    #+#             */
-/*   Updated: 2025/01/22 16:17:27 by chuhlig          ###   ########.fr       */
+/*   Updated: 2025/01/22 16:59:48 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -66,9 +66,11 @@ static char  *find_in_path(char *cmd, t_env *env, int *return_code)
        char    *cur_path;
        char    *cmd_path;
        char    **path;
+       char **path_start;
 
 
        path = get_split_path(env);
+       path_start = path;
        cmd_path = NULL;
        while (*path)
        {
@@ -76,17 +78,18 @@ static char *find_in_path(char *cmd, t_env *env, int *return_code)
                        free(cmd_path);
                cur_path = ft_strjoin(*path, "/");
                if (!cur_path)
-                       return (NULL);
+                       return (ft_free_split(path_start), NULL);
                cmd_path = ft_strjoin(cur_path, cmd);
                free(cur_path);
                if (!cmd_path)
-                       return (NULL);
+                       return (ft_free_split(path_start), NULL);
                if (access(cmd_path, X_OK) != -1)
-                       return (cmd_path);
+                       return (ft_free_split(path_start), cmd_path);
                path++;
        }
        *return_code = 127;
        free(cmd_path);
+       ft_free_split(path_start);
        command_not_found_error(cmd);
        return (NULL);
 }
index 21f8d9ffa6c274f55e9d270f05a5afe7886264c9..f0383a2a145f4b4a548736dfbdce84d616e1cb3c 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/06/27 11:21:03 by dkaiser           #+#    #+#             */
-/*   Updated: 2025/01/22 15:15:31 by chuhlig          ###   ########.fr       */
+/*   Updated: 2025/01/22 17:01:05 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -51,7 +51,7 @@ t_node        *new_cmd_node(char **args, t_redirection redirs[2],
                node->content.cmd.redirs[0] = redirs[0];
                node->content.cmd.redirs[1] = redirs[1];
                node->content.cmd.create_files = create_files;
-               // free(redirs);
+               free(redirs);
                redirs = NULL;
                return (node);
        }