MiniDevil
As beautiful as a shell
Environment variable management prototypes. More...
#include "structs.h"
Include dependency graph for env.h:
This graph shows which files directly or indirectly include this file:Environment variable management prototypes.
Definition in file env.h.
Functions | |
| t_env * | init_env (char **envp) |
| Initialize the environment linked list from main()'s envp. More... | |
| t_env * | create_env_node (char *env_string) |
| Create a single environment node from a KEY=value string. More... | |
| void | add_env_node (t_env **head, t_env *new_node) |
| Add a node to the end of the environment linked list. More... | |
| char * | get_env_value (t_env *env_list, char *key) |
| Look up an environment variable's value by its key. More... | |
| int | set_env_value (t_env **env_list, char *key, char *value) |
| Set or create an environment variable. More... | |
| void | handle_shlvl (t_env **env_list) |
| Increment the SHLVL environment variable. More... | |
| void | ensure_pwd (t_env **env_list) |
| Ensure PWD exists in the environment. More... | |
| void | free_env_list (t_env **env_list) |
| Free all nodes in the env linked list. More... | |
| int | env_list_size (t_env *env_list) |
| Count the number of nodes in the environment list. More... | |
| char ** | env_to_array (t_env *env) |
| Convert the env linked list to a NULL terminated string array. More... | |
| t_env* init_env | ( | char ** | envp | ) |
Initialize the environment linked list from main()'s envp.
| envp | NULL terminated string array from main() |
Definition at line 27 of file env_init.c.
References add_env_node(), create_env_node(), ensure_pwd(), free_env_list(), and handle_shlvl().
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:| t_env* create_env_node | ( | char * | env_string | ) |
Create a single environment node from a KEY=value string.
Allocate a t_env_node and populate key/value by splitting at the =
= are rejected (return NULL)| env_string | KEY=value string |
Definition at line 91 of file env_init.c.
References t_env::next, t_env::prev, and set_env_key_value().
Referenced by create_new_var(), and init_env().
Here is the call graph for this function:
Here is the caller graph for this function:Add a node to the end of the environment linked list.
| head | Pointer to list head pointer |
| new_node | Node to add |
Definition at line 121 of file env_init.c.
References t_env::next, and t_env::prev.
Referenced by create_new_var(), export_no_value(), and init_env().
Here is the caller graph for this function:| char* get_env_value | ( | t_env * | env_list, |
| char * | key | ||
| ) |
Look up an environment variable's value by its key.
| env_list | List head to search |
| key | Variable name to find |
Definition at line 23 of file env_operations.c.
References t_env::key, t_env::next, and t_env::value.
Referenced by ensure_pwd(), expand_tilde(), find_cmd_path(), get_append_value(), get_cd_path(), get_home_path(), handle_shlvl(), and process_dollar().
Here is the caller graph for this function:| int set_env_value | ( | t_env ** | env_list, |
| char * | key, | ||
| char * | value | ||
| ) |
Set or create an environment variable.
It first tries to update and existing variable, and if the key is not found, it creates a new node and adds it to the list
| env_list | Pointer to list head pointer |
| key | Variable name |
| value | New value |
Definition at line 115 of file env_operations.c.
References create_new_var(), and update_existing_var().
Referenced by ensure_pwd(), export_append(), export_assign(), handle_shlvl(), and update_pwd_vars().
Here is the call graph for this function:
Here is the caller graph for this function:| void handle_shlvl | ( | t_env ** | env_list | ) |
Increment the SHLVL environment variable.
| env_list | Pointer to list head pointer |
Definition at line 24 of file env_utils.c.
References get_env_value(), and set_env_value().
Referenced by init_env().
Here is the call graph for this function:
Here is the caller graph for this function:| void ensure_pwd | ( | t_env ** | env_list | ) |
Ensure PWD exists in the environment.
If it's not already set, it reads the current working directory via getcwd() and creates the variable
| env_list | Pointer to list head pointer |
Definition at line 51 of file env_utils.c.
References get_env_value(), and set_env_value().
Referenced by init_env().
Here is the call graph for this function:
Here is the caller graph for this function:| void free_env_list | ( | t_env ** | env_list | ) |
Free all nodes in the env linked list.
| env_list | Pointer to list head pointer |
Definition at line 69 of file env_utils.c.
References t_env::key, t_env::next, and t_env::value.
Referenced by child_execute(), exec_child(), exec_left_pipe_child(), exec_right_pipe_child(), init_env(), and main().
Here is the caller graph for this function:| int env_list_size | ( | t_env * | env_list | ) |
Count the number of nodes in the environment list.
| env_list | List head |
Definition at line 91 of file env_utils.c.
References t_env::next.
Referenced by env_to_array().
Here is the caller graph for this function:| char** env_to_array | ( | t_env * | env | ) |
Convert the env linked list to a NULL terminated string array.
Builds a char** destined to execve(). Each entry is in a KEY=value string
| env | List head |
Definition at line 107 of file env_conversion.c.
References env_list_size(), and fill_env_array().
Referenced by prepare_exec().
Here is the call graph for this function:
Here is the caller graph for this function: