mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-05-11 23:18:46 +02:00
「🔨」 fix(exec/check_file): check if path is a directory
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user