36 fd = open(file, O_RDONLY);
38 fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
40 fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0644);
43 ft_putstr_fd(
"minishell: ", STDERR_FILENO);
65 target = STDIN_FILENO;
67 target = STDOUT_FILENO;
68 saved_fd = dup(target);
71 perror(
"minishell: error on dup");
74 if (dup2(fd, target) == -1)
77 perror(
"minishell: error on dup2");
97 target = STDIN_FILENO;
99 target = STDOUT_FILENO;
100 dup2(saved_fd, target);
int executor(t_ast *node, t_shell *shell)
Main AST executor that dispatches by node type.
Executor prototypes for commands, pipes, redirections & heredocs.
int setup_redirection(int fd, t_node_type type)
Redirect STDIN or STDOUT to fd, saving the original.
int open_redir_file(char *file, t_node_type type)
Open a file for redirection (based on the redirection type)
int handle_redir(t_ast *node, t_shell *shell)
Execute a redirection node.
void restore_fd(int saved_fd, t_node_type type)
Restore a previously saved file descriptor.
t_node_type
AST node types.
t_ast_data data
cmd, redir or binary data
t_node_type type
To determine which union member to pick.
Redirection data inside AST node.
int heredoc_fd
Heredoc pipe fd (-1 if not used)
char * file
Target filename or delimiter.
struct s_ast * cmd
Command subtree.