Changed comportment on error for check_path functions

This commit is contained in:
Tanguy Maze 2019-10-18 14:17:34 +02:00
parent d22bc173f1
commit cfd4a67957
2 changed files with 13 additions and 10 deletions

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/20 11:43:53 by tmaze #+# #+# */
/* Updated: 2019/09/27 16:21:14 by tmaze ### ########.fr */
/* Updated: 2019/10/18 14:17:12 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/26 16:25:00 by tmaze #+# #+# */
/* Updated: 2019/10/10 14:05:31 by tmaze ### ########.fr */
/* Updated: 2019/10/18 14:10:59 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
@ -39,18 +39,20 @@ char *check_path_slash(char *exec)
if ((i = access(exec, F_OK)) != 0)
put_error(exec, "no such file or directory");
if (i != 0)
return (exec);
return (NULL);
if ((i = stat(exec, &info)) != 0)
put_error(exec, "can't determine info");
if (i != 0)
return (exec);
return (NULL);
if (!S_ISREG(info.st_mode))
{
put_error(exec, "not an executable file");
return (exec);
return (NULL);
}
if ((i = access(exec, X_OK)) != 0)
put_error(exec, "permission denied");
if (i != 0)
return (NULL);
return (exec);
}
@ -64,24 +66,24 @@ char *check_path_dot(char *exec, t_env *env)
|| path->val == NULL || (tmp = ft_strjoin(path->val, "/")) == NULL)
{
put_error(exec, "memory error");
return (exec);
return (NULL);
}
if ((ret = ft_strjoin(tmp, exec)) == NULL)
put_error(exec, "memory error");
ft_strdel(&tmp);
if (ret == NULL)
return (exec);
return (NULL);
if (access(ret, F_OK) == 0)
{
if (access(ret, X_OK) == 0)
return (ret);
return (exec);
put_error(exec, "permission denied");
ft_strdel(&ret);
return (exec);
return (NULL);
}
put_error(exec, "no such file or directory");
ft_strdel(&ret);
return (exec);
return (NULL);
}
char *check_path(char *exec, t_env *env)
@ -165,6 +167,7 @@ int exec_cmd(char **argv, t_env **env)
if (ft_strcmp(path, argv[0]) != 0)
ft_strdel(&path);
ft_del_words_tables(&env_tab);
lstdel(env);
exit(-1);
}
else if (ret == -1)