diff options
| author | Dominik Kaiser | 2024-05-08 13:05:37 +0200 |
|---|---|---|
| committer | GitHub | 2024-05-08 13:05:37 +0200 |
| commit | 50fd99cba74b758be23aafc4f76b5e63ef86977f (patch) | |
| tree | 1fa796501488d746f2d22c7bee80e5212dc830cc /src/env_utils.c | |
| parent | b05f8b0d22aa0bcf2d993d56b62055e042d55853 (diff) | |
| parent | 334aaa56cd3963f171afec6e852b9c07ad613828 (diff) | |
| download | pipex-50fd99cba74b758be23aafc4f76b5e63ef86977f.tar.gz pipex-50fd99cba74b758be23aafc4f76b5e63ef86977f.zip | |
Merging dev into master
This should be all.
Diffstat (limited to 'src/env_utils.c')
| -rw-r--r-- | src/env_utils.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/env_utils.c b/src/env_utils.c new file mode 100644 index 0000000..4b507a2 --- /dev/null +++ b/src/env_utils.c @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* env_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/02 16:19:31 by dkaiser #+# #+# */ +/* Updated: 2024/05/08 11:40:01 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "pipex.h" + +char **get_split_path(char *envp[]) +{ + char *path; + + while (!ft_strnstr(*envp, "PATH=", 5)) + envp++; + if (!*envp) + return (NULL); + path = *envp + 5; + return (ft_split(path, ':')); +} + +char *get_pwd(char *envp[]) +{ + while (!ft_strnstr(*envp, "PWD=", 4)) + envp++; + if (!*envp) + return (NULL); + return (*envp + 4); +} + +char *find_in_path(char *cmd, char **path) +{ + char *cur_path; + char *cmd_path; + + cmd_path = NULL; + while (*path) + { + if (cmd_path) + free(cmd_path); + cur_path = ft_strjoin(*path, "/"); + if (!cur_path) + return (NULL); + cmd_path = ft_strjoin(cur_path, cmd); + free(cur_path); + if (!cmd_path) + return (NULL); + if (access(cmd_path, X_OK) != -1) + return (cmd_path); + path++; + } + return (NULL); +} |
