minishell
Minishell Project for École 42
|
Utility functions for variable expansion. More...
#include "minishell.h"
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_expander * | init_expander (char *str) |
Initializes the expander struct for variable expansion. | |
void | free_exp (t_expander *exp) |
Frees resources associated with the expander struct. | |
Utility functions for variable expansion.
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.
[in] | exp | A pointer to the expander struct to be freed. |
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.
s | The input string. |
c | The character to concatenate. |
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.
s1 | The first input string. |
s2 | The second input string. |
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.
[in] | str | The input string to be expanded. |
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.
[in] | res | The original string to be reallocated. |
[in] | pos | The current position in the result string. |