diff options
| author | Dominik Kaiser | 2024-05-07 15:18:01 +0200 |
|---|---|---|
| committer | Dominik Kaiser | 2024-05-07 15:18:01 +0200 |
| commit | 7af46f10e23296baa72b70e5fbc72eb35e2a9b01 (patch) | |
| tree | 14d0f86716a7bd32b82c18985af4649fc46611ef /src/input_handling.c | |
| parent | bf5ee9f9aba9f8c5ec34f103e8848daae76f3c15 (diff) | |
| download | pipex-7af46f10e23296baa72b70e5fbc72eb35e2a9b01.tar.gz pipex-7af46f10e23296baa72b70e5fbc72eb35e2a9b01.zip | |
Add changes from input_handling
This is not how it should be done, but I just need to finish this quickly.
Diffstat (limited to 'src/input_handling.c')
| -rw-r--r-- | src/input_handling.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/input_handling.c b/src/input_handling.c new file mode 100644 index 0000000..e4bf7d6 --- /dev/null +++ b/src/input_handling.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* input_handling.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/02 12:13:23 by dkaiser #+# #+# */ +/* Updated: 2024/05/07 15:17:19 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "pipex.h" +#include <fcntl.h> +#include <stdlib.h> +#include <unistd.h> + +static char **get_cmds(int argc, char *argv[], char *envp[]) +{ + char **cmds; + int i; + char **path; + char *pwd; + + cmds = malloc(sizeof(char *) * (argc - 2)); + if (!cmds) + return (NULL); + path = get_split_path(envp); + // TODO: Free on fail + pwd = get_pwd(envp); + i = 2; + while (i < argc - 1) + { + cmds[i - 2] = get_cmd_path(argv[i], path, pwd); + i++; + } + i = 0; + while (path[i]) + free(path[i++]); + free(path); + return (cmds); +} + +t_pxdata *get_pxdata(int argc, char *argv[], char *envp[]) +{ + t_pxdata *result; + + result = malloc(sizeof(t_pxdata)); + if (!result) + return (NULL); // TODO: Check if an error message needs to be sent + result->in_fd = open(argv[1], O_RDONLY); + result->out_fd = open(argv[--argc], O_WRONLY | O_CREAT | O_TRUNC); + result->cmds = get_cmds(argc, argv, envp); + return (result); +} |
