26#include "../utils/utils.h"
28char **args_split(
char const *s);
29char *
get_cmd(
char **paths,
char *name);
31static int _dispatch(
char **paths,
char **argv,
char **envp,
int *in_out)
38 ft_printf(
"%>Command not found: %s\n", 2, argv[0]);
41 if (access(cmd, X_OK))
43 ft_printf(
"%>No access to execute \"%s\"\n", 2, cmd);
46 if (dup2(in_out[0], 0) == -1)
47 return ((
int)
err(
"dup2()", (
void *) 1));
48 if (dup2(in_out[1], 1) == -1)
49 return ((
int)
err(
"dup2()", (
void *) 1));
50 execve(cmd, argv, envp);
52 ft_printf(
"%>execve() failed for \"%s\": %s\n", 2, cmd, strerror(errno));
67void dispatch(
char **paths,
char *args,
char **envp,
int *in_out)
72 if (in_out[0] == -1 || in_out[1] == -1)
81 code = _dispatch(paths, child_argv, envp, in_out);
85 ft_printf(
"%>Could not split arguments \"%s\": %s\n",
86 2, args, strerror(errno));
void ** arr_free(void **arr)
Free each element in a null-terminated array, and then the array itself.
int ft_printf(const char *format,...)
Prints and formats a variable set of arguments.
void dispatch(char **paths, char *args, char **envp, int *in_out)
Dispatch child process with argument string args, environment envp, and stdin / stdout in_out[0] / in...
char * get_cmd(char **paths, char *name)
Find and return the first existing file with called name from the array of paths.
void * err(const char *str, void *retval)
Wrapper around perror() that always returns retval.
char ** ft_split(char const *s, char c)
Split string s by characer c into allocated array of strings, with NULL as the last element.