-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipex.h
69 lines (60 loc) · 2.23 KB
/
pipex.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbin-nas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/11 11:18:10 by mbin-nas #+# #+# */
/* Updated: 2022/11/11 11:18:10 by mbin-nas ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PIPEX_H
# define PIPEX_H
//* Main Libraries
# include <fcntl.h>
# include <stdbool.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <sys/types.h>
# include <sys/wait.h>
# include <unistd.h>
//? Error Files handling
# define ERR_INFILE "Infile Error\n"
# define ERR_OUTFILE "Outfile Error\n"
# define ERR_INPUT "Invalid number of arguments.\n"
# define ERR_PIPE "Pipe Error\n"
# define ERR_CMD "Command not found\n"
# define ERR_PATH "Path not found\n"
//// Struct definintion
typedef struct pipex
{
pid_t pid1;
pid_t pid2;
int fd[2];
int infile;
int outfile;
char *path;
char **cmd_path;
char **cmd_arg;
char *cmd;
} t_pipex;
//// Pipex functions
char *get_command(char **path, char *cmd);
void first_child_process(t_pipex pipex, char *argv[], char *envp[]);
void second_child_process(t_pipex pipex, char *argv[], char *envp[]);
void close_pipes(t_pipex *pipex);
void free_parent(t_pipex *pipex);
void free_childs(t_pipex *pipex);
char *find_path(char **envp);
////Libft Functions
char **ft_split(char const *str, char c);
char *ft_strjoin(char const *str1, char const *str2);
size_t ft_strlen(const char *c);
int ft_strncmp(const char *s1, const char *s2, size_t num);
char *ft_substr(char const *s, unsigned int start, size_t len);
//! Error messages
int message_error(char *error);
void perror_message(char *err);
#endif