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

Utility Functions for handling paths from the input. More...

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

Functions

bool handle_redirections_single_child (t_shell *shell)
 Handle redirections for single non-builtin command in child process.
 
char * get_absolute_path (t_shell *shell)
 Transform the non-absolut path into one.
 
void check_errno (t_shell *shell, char *path)
 Check and handle errors related to command execution.
 
void get_path_error (char *str)
 Handle errors when obtaining an empty path to an executable.
 
char * get_path (t_shell *shell, bool printerror)
 Get the path to an executable or convert it to an absolute path.
 

Detailed Description

Utility Functions for handling paths from the input.

This file contains utility functions for handling child processes in the Minishell project. It includes functions for handling redirections, obtaining and converting executable paths, checking for execution permission, and handling errors related to command execution.

Function Documentation

◆ check_errno()

void check_errno ( t_shell shell,
char *  path 
)

Check and handle errors related to command execution.

The check_errno function checks the value of the errno variable and sets the appropriate exit code and error message based on whether the command was not found or permission was denied.

Parameters
[in]shellA pointer to the shell struct containing the executor.
[in]pathThe path to the executable.

◆ get_absolute_path()

char * get_absolute_path ( t_shell shell)

Transform the non-absolut path into one.

The get_absolute_path function constructs the absolute path to an executable by combining it with each directory in the PATH environment variable. If the provided executable path is not absolute and is found in PATH, it is converted to an absolute path.

Parameters
[in]shellA pointer to the shell struct.
Returns
The absolute path to the executable if found; otherwise, the original executable name (if not in PATH).

◆ get_path()

char * get_path ( t_shell shell,
bool  printerror 
)

Get the path to an executable or convert it to an absolute path.

The function checks if the input for the command is already an absolute path. If not, it transforms the input to have the correct format else if just copies the absolute path into the path variable.

Parameters
[in]shellA pointer to the shell struct.
Returns
The path to the executable or NULL in case of an error.

◆ get_path_error()

void get_path_error ( char *  str)

Handle errors when obtaining an empty path to an executable.

The get_path_error function sets the errno and exit code for when the path is empty or the executable was not found and prints an error message.

Parameters
[in]strThe name of the executable.

◆ handle_redirections_single_child()

bool handle_redirections_single_child ( t_shell shell)

Handle redirections for single non-builtin command in child process.

The handle_redirections_single_child 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.