From 1c676c8f2f393ede7dbbc47aa7ca8cb6e9bee711 Mon Sep 17 00:00:00 2001 From: narnaud Date: Sat, 7 May 2022 00:31:34 +0200 Subject: [PATCH] fixed local find in PATH e.g.'./cat' --- README.md | 2 +- caller.c | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 2aa2986..2a27351 100755 --- a/README.md +++ b/README.md @@ -15,4 +15,4 @@ ## Issues : -- error using unknow command with valgrind +## Notes : diff --git a/caller.c b/caller.c index 99f22ca..ecf9841 100755 --- a/caller.c +++ b/caller.c @@ -54,17 +54,20 @@ void exe(t_datas *datas, t_command *cmd) if (ft_strchr(cmd->argv[0], '/')) execve(cmd->argv[0], cmd->argv, datas->envp); - path_dirs = ft_split(getenv("PATH"), ':'); - while (path_dirs) + else { - path_length = ft_strlen(*path_dirs) + ft_strlen(cmd->argv[0]) + 2; - path = ft_calloc(path_length, sizeof(char)); - ft_memcpy(path, *path_dirs, ft_strlen(*path_dirs)); - ft_memcpy(path + ft_strlen(*path_dirs),"/", 1); - ft_memcpy(path + ft_strlen(*path_dirs) + 1, cmd->argv[0], ft_strlen(cmd->argv[0])); - execve(path, cmd->argv, datas->envp); - free(path); - path_dirs++; + path_dirs = ft_split(getenv("PATH"), ':'); + while (path_dirs) + { + path_length = ft_strlen(*path_dirs) + ft_strlen(cmd->argv[0]) + 2; + path = ft_calloc(path_length, sizeof(char)); + ft_memcpy(path, *path_dirs, ft_strlen(*path_dirs)); + ft_memcpy(path + ft_strlen(*path_dirs),"/", 1); + ft_memcpy(path + ft_strlen(*path_dirs) + 1, cmd->argv[0], ft_strlen(cmd->argv[0])); + execve(path, cmd->argv, datas->envp); + free(path); + path_dirs++; + } } }