int i;
char *temp;
char *path;
char **paths;
struct stat buf;
temp = search_env("PATH");
paths = ft_split(temp, ':');
i = -1;
while (paths[++i])
{
temp = ft_strjoin("/", cmd);
path = ft_strjoin(paths[i], temp);
free(temp);
if (stat(path, &buf) == 0)
{
cmd = path;
break ;
}
free(path);
}
free_double_arr(paths);
return (cmd);
}
cmd
- 경로를 찾을 명령어
return - 경로를 찾을 경우 경로+멸령어 → ex. /bin/ls
없으면 명령어만 반환 → ex. exit