/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* check_path_slach_cd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/01 15:29:57 by tmaze #+# #+# */ /* Updated: 2020/02/01 15:31:19 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" char *check_path_slash_cd(char *exec) { int i; struct stat info; struct stat info2; if (exec[0] == '/') { if ((i = access(exec, F_OK)) != 0) return (put_error_cd(exec, "no such file or directory")); if ((i = lstat(exec, &info)) != 0) return (put_error_cd(exec, "can't determine info")); if ((S_ISLNK(info.st_mode) && ((i = stat(exec, &info2)) != 0 || !S_ISDIR(info2.st_mode))) && !S_ISDIR(info.st_mode)) return (put_error_cd(exec, "not a directory")); if ((i = access(exec, X_OK)) != 0) return (put_error_cd(exec, "permission denied")); return (exec); } return (NULL); }