Browse Source

fixed local find in PATH e.g.'./cat'

master
narnaud 3 years ago
parent
commit
1c676c8f2f
  1. 2
      README.md
  2. 23
      caller.c

2
README.md

@ -15,4 +15,4 @@
## Issues : ## Issues :
- error using unknow command with valgrind ## Notes :

23
caller.c

@ -54,17 +54,20 @@ void exe(t_datas *datas, t_command *cmd)
if (ft_strchr(cmd->argv[0], '/')) if (ft_strchr(cmd->argv[0], '/'))
execve(cmd->argv[0], cmd->argv, datas->envp); execve(cmd->argv[0], cmd->argv, datas->envp);
path_dirs = ft_split(getenv("PATH"), ':'); else
while (path_dirs)
{ {
path_length = ft_strlen(*path_dirs) + ft_strlen(cmd->argv[0]) + 2; path_dirs = ft_split(getenv("PATH"), ':');
path = ft_calloc(path_length, sizeof(char)); while (path_dirs)
ft_memcpy(path, *path_dirs, ft_strlen(*path_dirs)); {
ft_memcpy(path + ft_strlen(*path_dirs),"/", 1); path_length = ft_strlen(*path_dirs) + ft_strlen(cmd->argv[0]) + 2;
ft_memcpy(path + ft_strlen(*path_dirs) + 1, cmd->argv[0], ft_strlen(cmd->argv[0])); path = ft_calloc(path_length, sizeof(char));
execve(path, cmd->argv, datas->envp); ft_memcpy(path, *path_dirs, ft_strlen(*path_dirs));
free(path); ft_memcpy(path + ft_strlen(*path_dirs),"/", 1);
path_dirs++; 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++;
}
} }
} }

Loading…
Cancel
Save