minishell
Minishell Project for École 42
Loading...
Searching...
No Matches
single_builtin_utils.c File Reference

Utility Functions for Handling external Commands. More...

#include "minishell.h"
Include dependency graph for single_builtin_utils.c:

Functions

bool handle_redirections_single_builtin (t_shell *shell)
 Handle redirections for a single non-builtin command.
 
void saving_stds (int *stdin_cpy, int *stdout_cpy)
 Save the stdin and stdout file descriptors.
 
bool restore_stds (int stdin_cpy, int stdout_cpy)
 Restore the stdin and stdout file descriptors.
 

Detailed Description

Utility Functions for Handling external Commands.

This file contains utility functions to save, restore and set file descriptors while executing an external command. It checks for errors while duplicating/handling signals and sets the correct exit value.

Function Documentation

◆ handle_redirections_single_builtin()

bool handle_redirections_single_builtin ( t_shell shell)

Handle redirections for a single non-builtin command.

The handle_redirections_single_builtin function handles redirections for a single non-builtin command. It duplicates the file descriptors needed by the child process and closes back the copy.

Parameters
[in,out]shellA pointer to the shell struct.
Returns
Returns true if redirections are successfully handled, or false if an error occurs.

◆ restore_stds()

bool restore_stds ( int  stdin_cpy,
int  stdout_cpy 
)

Restore the stdin and stdout file descriptors.

The restore_stds function restores the standard input and output file descriptors by duplicating the saved file descriptors back to stdin and stdout. It also handles errors if somehow the restoration fails.

Parameters
[in]stdin_cpyThe duplicated stdin file descriptor.
[in]stdout_cpyThe duplicated stdout file descriptor.
Returns
Returns true if the restoration is successful, or false if an error occurs.

◆ saving_stds()

void saving_stds ( int *  stdin_cpy,
int *  stdout_cpy 
)

Save the stdin and stdout file descriptors.

The saving_stds function saves the stdin and stdout file descriptors by duplicating and storing them.

Parameters
[out]stdin_cpyA pointer to store the duplicated stdin file descriptor.
[out]stdout_cpyA pointer to store the duplicated stdout file descriptor.