24#include "../mandatory/utils/utils.h"
28int here_doc(
char *limiter,
int *in_out);
30int dispatcher(
int n,
char ***str_arrs,
int *in_out);
41static void _input(
int argc,
char **argv,
int *is_here_doc,
int *trunc_append)
44 *trunc_append = O_TRUNC;
45 if (argv[1] && !
ft_strncmp(
"here_doc", argv[1], 8))
48 *trunc_append = O_APPEND;
50 if (argc < (5 + *is_here_doc))
52 ft_printf(
"%>Too few arguments: %d. Expected %d+\n",
53 2, argc - 1, 4 + *is_here_doc);
58static int _open(
char *name,
int flags,
int mode)
62 fd = open(name, flags, mode);
64 ft_printf(
"%>Failed to open \"%s\": %s\n", 2, name, strerror(errno));
68int main(
int argc,
char **argv,
char **envp)
76 _input(argc, argv, &is_here_doc, &trunc_append);
77 in_out[1] = _open(argv[argc - 1], O_WRONLY | O_CREAT | trunc_append,
78 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
80 in_out[0] = _open(argv[1], O_RDONLY, 0);
85 (
char **[]){paths, argv + 2 + is_here_doc, envp}, in_out);
void ** arr_free(void **arr)
Free each element in a null-terminated array, and then the array itself.
static void _input(int argc, char **argv, int *is_here_doc, int *trunc_append)
Check if in here_doc mode, verify arguments count accordingly, and set append or truncate accordingly...
char ** get_paths(char **envp)
Create a null-terminated, unique array of paths from the environment pointer envp....
int dispatcher(int n, char ***str_arrs, int *in_out)
Dispatch n child processes with argument strings str_arrs[1][i], environment pointer str_arrs[2],...
int here_doc(char *limiter, int *in_out)
Capture multiline input from stdin and write to a pipe readable from in_out[0] until a line containin...
int ft_printf(const char *format,...)
Prints and formats a variable set of arguments.
int ft_strncmp(const char *s1, const char *s2, size_t n)
Compare up to n characters of string s1 with string s2.