maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
redirect_append.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* redirect_append.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/07/11 14:32:11 by dmdemirk #+# #+# */
9/* Updated: 2024/07/11 14:54:19 by dmdemirk ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "shell.h"
14#include "tokens.h"
15#include "redirection.h"
16#include "execute.h"
17#include <sys/wait.h>
18
19int redirect_append(t_ast *node, t_ms_data *data);
20
32{
33 pid_t pid;
34 int status;
35
36 pid = fork();
37 if (pid == -1)
38 return (1);
39 if (pid == 0)
40 {
41 data->std_out = open_file(node->right, ">>");
42 if (data->std_out == -1)
43 return (1);
44 execute_ast(node->left, data);
45 exit(0);
46 }
47 waitpid(pid, &status, 0);
48 return (WEXITSTATUS(status));
49}
int execute_ast(t_ast *node, t_ms_data *data)
execute Abstract Syntax Tree
Definition execute.c:38
int redirect_append(t_ast *node, t_ms_data *data)
redirect append ">>" to the end of the file output
int open_file(t_ast *node, char *direction)
open file in the context of redirection
Definition utils.c:34
Definition tokens.h:50
struct s_ast * right
Definition tokens.h:54
struct s_ast * left
Definition tokens.h:53
int std_out
Definition shell.h:27