maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
redirect_in.c File Reference
#include "tokens.h"
#include "shell.h"
#include "redirection.h"
#include "execute.h"
#include <string.h>
#include <sys/wait.h>
Include dependency graph for redirect_in.c:

Go to the source code of this file.

Functions

int redirect_in (t_ast *node, t_ms_data *data)
 redirection input in context of executing AST
 

Function Documentation

◆ redirect_in()

int redirect_in ( t_ast node,
t_ms_data data 
)

redirection input in context of executing AST

--

  • Parameters
    nodecurrent node in the AST
  • Parameters
    dataminishell structure data
  • Returns
    status:
  • 0: success
  • 1: error

Definition at line 38 of file redirect_in.c.

39{
40 pid_t pid;
41
42 pid = fork();
43 if (pid == -1)
44 return (1);
45 if (pid == 0)
46 {
47 data->std_in = open_file(node->right, "<");
48 if (data->std_in == -1)
49 return (1);
50 execute_ast(node->left, data);
51 exit(0);
52 }
53 waitpid(pid, &data->exit_status, 0);
54 return (0);
55}
int execute_ast(t_ast *node, t_ms_data *data)
execute Abstract Syntax Tree
Definition execute.c:38
int open_file(t_ast *node, char *direction)
open file in the context of redirection
Definition utils.c:34
struct s_ast * right
Definition tokens.h:54
struct s_ast * left
Definition tokens.h:53
int exit_status
Definition shell.h:30
int std_in
Definition shell.h:26

References execute_ast(), s_ms_data::exit_status, s_ast::left, open_file(), s_ast::right, and s_ms_data::std_in.

Referenced by execute_ast().

Here is the call graph for this function:
Here is the caller graph for this function: