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

Utility functions for variable expansion. More...

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

Functions

char * ft_charjoin_expander (char const *s, char const c)
 Concatenates character to the end of a string.
 
char * ft_strjoin_expander (char const *s1, char const *s2)
 Concatenates two strings and expands the memory as needed.
 
char * realloc_str (char *res, int pos)
 Reallocates memory for a string.
 
t_expanderinit_expander (char *str)
 Initializes the expander struct for variable expansion.
 
void free_exp (t_expander *exp)
 Frees resources associated with the expander struct.
 

Detailed Description

Utility functions for variable expansion.

Function Documentation

◆ free_exp()

void free_exp ( t_expander exp)

Frees resources associated with the expander struct.

This function deallocates memory used by the expander struct and its associated fields. It ensures that no memory leaks occur during variable expansion.

Parameters
[in]expA pointer to the expander struct to be freed.

◆ ft_charjoin_expander()

char * ft_charjoin_expander ( char const *  s,
char const  c 
)

Concatenates character to the end of a string.

This function takes an input string s and a character c, and concatenates the character to the end of the string. The memory for the resulting string is dynamically allocated to accommodate the additional character. The memory for the original string is freed before returning the result.

Parameters
sThe input string.
cThe character to concatenate.
Returns
A pointer to the concatenated string, or NULL if memory allocation fails.

◆ ft_strjoin_expander()

char * ft_strjoin_expander ( char const *  s1,
char const *  s2 
)

Concatenates two strings and expands the memory as needed.

This function takes two input strings, s1 and s2, and concatenates them into a new string. The memory for the resulting string is dynamically allocated to accommodate both input strings. The memory for s1 is freed before returning the result.

Parameters
s1The first input string.
s2The second input string.
Returns
A pointer to the concatenated string, or NULL if memory allocation fails.

◆ init_expander()

t_expander * init_expander ( char *  str)

Initializes the expander struct for variable expansion.

This function initializes the expander struct used during variable expansion. It allocates memory for various fields and sets their initial values.

Parameters
[in]strThe input string to be expanded.
Returns
A pointer to the initialized expander struct or NULL on allocation failure.

◆ realloc_str()

char * realloc_str ( char *  res,
int  pos 
)

Reallocates memory for a string.

This function reallocates memory for a string, extending its size while preserving its existing content. It is used to dynamically expand the result string during variable expansion.

Parameters
[in]resThe original string to be reallocated.
[in]posThe current position in the result string.
Returns
A pointer to the reallocated string or NULL on allocation failure.