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 :
- 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], '/'))
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++;
}
}
}

Loading…
Cancel
Save