diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-09-15 17:54:48 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-09-15 17:54:48 +0200 |
| commit | f626f2715ab696fdb326ed67256d012d86faef9f (patch) | |
| tree | f25f2d95688a89c662622e3c2f11786f27689713 /src/path.c | |
| parent | 170d0b74fa725196bca0fa549520d0d8bfa07576 (diff) | |
| download | minishell-f626f2715ab696fdb326ed67256d012d86faef9f.tar.gz minishell-f626f2715ab696fdb326ed67256d012d86faef9f.tar.bz2 minishell-f626f2715ab696fdb326ed67256d012d86faef9f.zip | |
Refactoring env, Removing bloat from utils, exec and env
Diffstat (limited to 'src/path.c')
| -rw-r--r-- | src/path.c | 30 |
1 files changed, 10 insertions, 20 deletions
@@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/27 15:51:01 by cacharle #+# #+# */ -/* Updated: 2020/09/15 13:36:34 by charles ### ########.fr */ +/* Updated: 2020/09/15 17:45:44 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,32 +17,21 @@ #include "minishell.h" -int path_check(char exec_path[PATH_MAX + 1], bool in_path) +static int st_path_check(char exec_path[PATH_MAX + 1], bool in_path) { struct stat statbuf; - /* char cwd[PATH_MAX + 1]; */ if (stat(exec_path, &statbuf) == -1) return (errorf_ret(127, "%s: %s\n", exec_path, strerror(errno))); if (S_ISDIR(statbuf.st_mode)) return (errorf_ret(126, "%s: Is a directory\n", exec_path)); - /* if (S_ISLNK(statbuf.st_mode)) */ - /* return (errorf_ret(127, "%s: command not found\n", exec_path)); */ if (!in_path && !(statbuf.st_mode & 0444)) return (errorf_ret(126, "%s: %s\n", exec_path, strerror(EACCES))); - /* if (*exec_path != '/') */ - /* { */ - /* getcwd(cwd, PATH_MAX + 1); */ - /* ft_strcat(cwd, "/"); */ - /* ft_strcat(cwd, exec_path); */ - /* ft_strcpy(exec_path, cwd); */ - /* } */ return (0); - - } -static bool st_dir_search(char *dirname, char *exec_name, char exec_path[PATH_MAX + 1]) +static bool st_dir_search( + char *dirname, char *exec_name, char exec_path[PATH_MAX + 1]) { DIR *dir; struct dirent *entry; @@ -63,7 +52,8 @@ static bool st_dir_search(char *dirname, char *exec_name, char exec_path[PATH_M return (false); } -int path_search(t_env env, char *exec_name, char exec_path[PATH_MAX + 1], bool print) +int path_search( + t_env env, char *exec_name, char exec_path[PATH_MAX + 1], bool print) { char *current_dir; char *collon; @@ -72,9 +62,9 @@ int path_search(t_env env, char *exec_name, char exec_path[PATH_MAX + 1], boo if (ft_strchr(exec_name, '/') != NULL) { ft_strcpy(exec_path, exec_name); - return (path_check(exec_path, false)); + return (st_path_check(exec_path, false)); } - if ((current_dir = env_search(env, "PATH")) == NULL) + if ((current_dir = env_search(env, "PATH", NULL)) == NULL) return (st_dir_search(getcwd(cwd, PATH_MAX + 1), exec_name, exec_path)); while ((collon = ft_strchr(current_dir, ':')) != NULL) { @@ -84,7 +74,7 @@ int path_search(t_env env, char *exec_name, char exec_path[PATH_MAX + 1], boo if (st_dir_search(current_dir, exec_name, exec_path)) { *collon = ':'; - return (path_check(exec_path, true)); + return (st_path_check(exec_path, true)); } *collon = ':'; current_dir = collon + 1; @@ -92,7 +82,7 @@ int path_search(t_env env, char *exec_name, char exec_path[PATH_MAX + 1], boo if (*current_dir == '\0') current_dir = getcwd(cwd, PATH_MAX + 1); if (st_dir_search(current_dir, exec_name, exec_path)) - return (path_check(exec_path, true)); + return (st_path_check(exec_path, true)); if (print) errorf("%s: command not found\n", exec_name); return (127); |
