Resolved infinite loop in extension revolving

WIP norming in cd
This commit is contained in:
Tanguy Maze
2020-01-24 00:33:56 +01:00
parent 4f7e1a56ef
commit 40718a99ac
3 changed files with 22 additions and 30 deletions

View File

@@ -6,18 +6,19 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/07 16:44:40 by tmaze #+# #+# */
/* Updated: 2019/11/11 01:09:36 by tmaze ### ########.fr */
/* Updated: 2020/01/23 23:37:53 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void put_error_cd(char *file, char *msg)
void *put_error_cd(char *file, char *msg)
{
ft_putstr("cd: ");
ft_putstr(file);
ft_putstr(": ");
ft_putendl(msg);
return (NULL);
}
char *check_path_slash_cd(char *exec)
@@ -29,22 +30,14 @@ char *check_path_slash_cd(char *exec)
if (exec[0] == '/')
{
if ((i = access(exec, F_OK)) != 0)
put_error_cd(exec, "no such file or directory");
if (i != 0)
return (NULL);
return (put_error_cd(exec, "no such file or directory"));
if ((i = lstat(exec, &info)) != 0)
put_error_cd(exec, "can't determine info");
if (i != 0)
return (NULL);
if (!S_ISDIR(info.st_mode) || (S_ISLNK(info.st_mode) && ((i = stat(exec, &info2)) != 0 || !S_ISDIR(info2.st_mode))))
{
put_error_cd(exec, "not a directory");
return (NULL);
}
return (put_error_cd(exec, "can't determine info"));
if (!S_ISDIR(info.st_mode) || (S_ISLNK(info.st_mode)
&& ((i = stat(exec, &info2)) != 0 || !S_ISDIR(info2.st_mode))))
return (put_error_cd(exec, "not a directory"));
if ((i = access(exec, X_OK)) != 0)
put_error_cd(exec, "permission denied");
if (i != 0)
return (NULL);
return (put_error_cd(exec, "permission denied"));
return (exec);
}
return (NULL);