minishell
Minishell Project for École 42
|
Utility Functions for Handling Child Processes. More...
#include "minishell.h"
Functions | |
int | get_size_environ (t_environ_node *current) |
Get the size of the environment list. | |
char ** | create_environ_array (t_environ_list *environ) |
Create the environment array based on the list size. | |
void | transform_error (char **environ_array) |
Error handling while copying the environment list into the array. | |
void | transform_helper (t_environ_node *current, char **environ_array) |
Copy environment variables into the env array. | |
char ** | transform_environ_array (t_shell *shell) |
Copy the environment variables into an array for execve. | |
Utility Functions for Handling Child Processes.
This file contains utility functions for handling child processes. It copies the list of environment variables in a 2D array so that it can be used by the execve function.
char ** create_environ_array | ( | t_environ_list * | environ | ) |
Create the environment array based on the list size.
The create_environ_array function allocates memory for the environment array. It gets the size of the list from get_size_environ and returns the allocated array.
[in] | environ | A pointer to the environment variable linked list. |
int get_size_environ | ( | t_environ_node * | current | ) |
Get the size of the environment list.
The get_size_environ function counts and returns the size of the list of environment variables.
[in] | current | A pointer to the head of the environment variable list. |
char ** transform_environ_array | ( | t_shell * | shell | ) |
Copy the environment variables into an array for execve.
The transform_environ_array function creates an environment array for execve. It first allocates memory for the environment array and then calls transform_helper to populate it with environment variable strings.
[in] | shell | A pointer to the shell struct. |
void transform_error | ( | char ** | environ_array | ) |
Error handling while copying the environment list into the array.
The transform_error function is called when an error occurs during the copying process. It frees the allocated memory for the array and reports an error.
[in] | environ_array | A pointer to the environment array to be freed. |
void transform_helper | ( | t_environ_node * | current, |
char ** | environ_array | ||
) |
Copy environment variables into the env array.
The transform_helper function is responsible for copying the linked list into the environment array used for execve calls. It allocates memory for each environment variable string and combines the key + value with an equal sign.
[in] | current | A pointer to the head of the environment variable list. |
[out] | environ_array | A pointer to the environment array. |