fixed file execution error handling

This commit is contained in:
mdev9
2024-03-06 10:21:23 +01:00
parent 4df96de4a3
commit d9b819165e
3 changed files with 48 additions and 17 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */
/* Updated: 2024/03/05 18:19:32 by marde-vr ### ########.fr */
/* Updated: 2024/03/06 10:19:58 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,3 +35,25 @@ void ft_exit(t_msh *msh, int exit_code)
free_msh(msh);
exit(exit_code);
}
int file_access(t_msh *msh, int *found)
{
if (open(msh->cmds->token, O_DIRECTORY) != -1)
{
ft_printf_fd(2, "minishell: %s: Is a directory\n", msh->cmds->token);
g_return_code = 126;
return (0);
}
if (access(msh->cmds->token, X_OK) != -1)
*found = 1;
else
{
ft_printf_fd(2, "minishell: %s: ", msh->cmds->token);
perror("");
g_return_code = 127;
if (access(msh->cmds->token, F_OK) != -1)
g_return_code = 126;
return (0);
}
return (1);
}