🔨」 fix(exec/check_file): check if path is a directory

This commit is contained in:
y-syo
2024-07-14 15:50:26 +02:00
parent fe0285a5b2
commit ac7684f45d
3 changed files with 29 additions and 6 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/09 19:25:18 by adjoly #+# #+# */
/* Updated: 2024/07/10 01:17:11 by adjoly ### ########.fr */
/* Updated: 2024/07/14 15:49:04 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -89,3 +89,25 @@ int switch_cmd_path(t_cmd *cmd, t_env *env)
return (-1);
return (0);
}
int check_file(char *cmd, char *input)
{
struct stat entry;
int status;
if (is_in_builtins(cmd))
return (0);
status = stat(cmd, &entry);
if (status)
{
printf("minishell : command not found: %s\n", input);
return (1);
}
if (!S_ISDIR(entry.st_mode) && !access(cmd, X_OK))
return (0);
if (S_ISDIR(entry.st_mode))
printf("minishell : %s is a directory.\n", input);
else
printf("minishell : command not found: %s\n", input);
return (1);
}