path of cmd ok

This commit is contained in:
hugogogo
2021-10-30 14:43:06 +02:00
parent 75987a117e
commit 0292425bc1
3 changed files with 134 additions and 64 deletions

View File

@@ -101,35 +101,37 @@ void handle_fd(t_token *token, t_cmd **cmd)
cmd[1]->fd_in = pipes_fd[0];
}
}
*/
int handle_builtin(t_token *token, t_cmd *cmd)
{
(void)token;
(void)cmd;
return (0);
}
void handle_cmd(char **argv, char **envp)
{
int i;
char **path;
char *cmd;
i = 0;
while (envp[i] && ft_strncmp(envp[i], "PATH=", 5))
i++;
path = ft_split(envp[i] + 5, ':'); // 5 = lentgh of "PATH="
i = -1;
while (*path && i != 0)
{
cmd = ft_strjoin(path[0], "/");
cmd = ft_strjoin(cmd, argv[0]);
i = access(cmd, X_OK);
path++;
}
argv[0] = cmd;
}
//int handle_builtin(t_token *token, t_cmd *cmd)
//{
// (void)token;
// (void)cmd;
// return (0);
//}
//
//void handle_cmd(char **argv, char **envp)
//{
// int i;
// char **path;
// char *cmd;
//
// i = 0;
// while (envp[i] && ft_strncmp(envp[i], "PATH=", 5))
// i++;
// path = ft_split(envp[i] + 5, ':'); // 5 = lentgh of "PATH="
// i = -1;
// while (*path && i != 0)
// {
// cmd = ft_strjoin(path[0], "/");
// cmd = ft_strjoin(cmd, argv[0]);
// i = access(cmd, X_OK);
// path++;
// }
// argv[0] = cmd;
//}
/*
t_cmd **fill_cmd(t_token *token, char **envp)
{
t_cmd **cmd;