MiniDevil As beautiful as a shell
env_utils.c File Reference

Environment utilities: handles SHLVL increment & PWD validation. More...

#include "env.h"
#include "libft.h"
+ Include dependency graph for env_utils.c:

Detailed Description

Environment utilities: handles SHLVL increment & PWD validation.

Definition in file env_utils.c.

Functions

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...
 

Function Documentation

◆ handle_shlvl()

void handle_shlvl ( t_env **  env_list)

Increment the SHLVL environment variable.

  • Reads the current SHLVL, increments it by 1 and writes back
  • If SHLVL doesn't exist, it initializes it to 1
Parameters
env_listPointer 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:

◆ ensure_pwd()

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

Parameters
env_listPointer 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:

◆ free_env_list()

void free_env_list ( t_env **  env_list)

Free all nodes in the env linked list.

Parameters
env_listPointer 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:

◆ env_list_size()

int env_list_size ( t_env env_list)

Count the number of nodes in the environment list.

Parameters
env_listList head
Returns
Number of nodes

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:

Go to the source code of this file.