small fixes

This commit is contained in:
Loic Deridder
2025-02-18 14:35:37 +01:00
parent afe1213db7
commit 06ffb44757
2 changed files with 11 additions and 9 deletions

View File

@@ -11,7 +11,9 @@
/* ************************************************************************** */ /* ************************************************************************** */
#include "../../includes/minishell.h" #include "../../includes/minishell.h"
#include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/stat.h>
int count_cmds(t_ast_n **pline) int count_cmds(t_ast_n **pline)
{ {
@@ -31,9 +33,10 @@ char *find_path(char *cmd, char **env)
char *path; char *path;
char **paths; char **paths;
int i; int i;
struct stat st;
if (access(cmd, F_OK) == 0 && access(cmd, X_OK) == 0) if (stat(cmd, &st) && S_ISREG(st.st_mode) && access(cmd, X_OK) == 0)
return (cmd); return (ft_strdup(cmd));
i = 0; i = 0;
while (env[i] && ft_strnstr(env[i], "PATH=", 5) == NULL) while (env[i] && ft_strnstr(env[i], "PATH=", 5) == NULL)
i++; i++;
@@ -50,8 +53,7 @@ char *find_path(char *cmd, char **env)
return (free_tab(paths), path); return (free_tab(paths), path);
free(path); free(path);
} }
free_tab(paths); return (free_tab(paths), NULL);
return (NULL);
} }
void return_error(char *arg, char *msg, int code, t_ast_n *node) void return_error(char *arg, char *msg, int code, t_ast_n *node)

View File

@@ -56,7 +56,7 @@ void free_msh(t_msh *msh)
close(msh->hist); close(msh->hist);
if (msh->here_fd != -1) if (msh->here_fd != -1)
close(msh->here_fd); close(msh->here_fd);
free(msh->input); ft_free(&msh->input);
ft_free(&msh->prev_input); ft_free(&msh->prev_input);
free(msh); free(msh);
} }