minishell
Minishell Project for École 42
|
Utility Functions for handling paths from the input. More...
#include "minishell.h"
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. | |
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.
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.
[in] | shell | A pointer to the shell struct containing the executor. |
[in] | path | The path to the executable. |
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.
[in] | shell | A pointer to the shell struct. |
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.
[in] | shell | A pointer to the shell struct. |
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.
[in] | str | The name of the executable. |
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.
[in,out] | shell | A pointer to the shell struct. |
true
if redirections are successfully handled, or false
if an error occurs.