-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipex.h
More file actions
87 lines (75 loc) · 2.64 KB
/
pipex.h
File metadata and controls
87 lines (75 loc) · 2.64 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipex.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: acastrov <acastrov@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/17 18:24:11 by acastrov #+# #+# */
/* Updated: 2025/01/04 18:05:51 by acastrov ### ########.fr */
/* */
/* ************************************************************************** */
// Global def
#ifndef PIPEX_H
# define PIPEX_H
// Libs
# include <fcntl.h>
# include <errno.h>
# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
# include <sys/types.h>
# include <sys/wait.h>
// Macros for error
# define SUCCESS 0
# define MALLOC_ERROR 1
# define FILE_ERROR 2
# define PIPE_ERROR 3
# define FORK_ERROR 4
// Structs
typedef struct s_fd_pipe
{
int in_fd;
int out_fd;
int fd[2];
} t_fd_pipe;
typedef struct s_cmd
{
char **cmd_paths;
char ***cmd_arg;
int cmd_count;
char *cmd_1;
char *cmd_2;
} t_cmd;
// Main pipex
int ft_pipex(char **argv, t_cmd cmd, t_fd_pipe fd_pipe);
int ft_init_pipex(t_cmd *cmd, int argc, char **argv, char **enpv);
int ft_child_1(t_cmd *cmd, t_fd_pipe *fd_pipe, char **enpv);
int ft_child_2(t_cmd *cmd, t_fd_pipe *fd_pipe, char **enpv);
// Args
int ft_parse_args(t_cmd *cmd, int argc, char **argv);
int ft_get_path(t_cmd *cmd, char **envp);
char *ft_find_path(char **envp);
// Free
int ft_free_cmd(t_cmd *cmd, int flag);
void ft_free_cmd_paths(char **cmd_paths);
void ft_free_cmd_arg(char ***cmd_arg);
int ft_free_fd_pipe(t_fd_pipe *fd_pipe, int flag);
// Check ft
int ft_check_files_cmd(t_cmd *cmd, char **argv);
int ft_check_files(char **argv);
int ft_check_cmd_1(t_cmd *cmd);
int ft_check_cmd_2(t_cmd *cmd);
// Open
int ft_open_fd(t_fd_pipe *fd_pipe, int argc, char **argv);
// Libft
char *ft_strchr(const char *s, int c);
char *ft_strdup(const char *s);
size_t ft_strlcat(char *dst, const char *src, size_t size);
size_t ft_strlcpy(char *dst, const char *src, size_t size);
size_t ft_strlen(const char *s);
char **ft_split(char const *s, char c);
int ft_strncmp(const char *s1, const char *s2, size_t n);
char *ft_strjoin(char const *s1, char const *s2);
char *ft_substr(char const *s, unsigned int start, size_t len);
#endif