aboutsummaryrefslogtreecommitdiff
path: root/src/path.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/path.c')
-rw-r--r--src/path.c30
1 files changed, 10 insertions, 20 deletions
diff --git a/src/path.c b/src/path.c
index 4e912ba..4949ba9 100644
--- a/src/path.c
+++ b/src/path.c
@@ -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);