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

Utility Functions for Handling Child Processes. More...

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

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.
 

Detailed Description

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.

Function Documentation

◆ create_environ_array()

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.

Parameters
[in]environA pointer to the environment variable linked list.
Returns
A dynamically allocated array of environment variable strings or NULL in case of an error.

◆ get_size_environ()

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.

Parameters
[in]currentA pointer to the head of the environment variable list.
Returns
The number of elements in the linked list.

◆ transform_environ_array()

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.

Parameters
[in]shellA pointer to the shell struct.
Returns
A dynamically allocated environment array or NULL in case of an error.

◆ transform_error()

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.

Parameters
[in]environ_arrayA pointer to the environment array to be freed.

◆ transform_helper()

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.

Parameters
[in]currentA pointer to the head of the environment variable list.
[out]environ_arrayA pointer to the environment array.