/* 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 */
/* */
/* ************************************************************************** */
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)
/* 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 */
/* */
/* ************************************************************************** */
char *cur_path;
char *cmd_path;
char **path;
+ char **path_start;
path = get_split_path(env);
+ path_start = path;
cmd_path = NULL;
while (*path)
{
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);
}
/* 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 */
/* */
/* ************************************************************************** */
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);
}