MiniDevil As beautiful as a shell
builtin_unset.c File Reference

Implements unset: removes env variables. More...

#include "builtins.h"
#include "libft.h"
+ Include dependency graph for builtin_unset.c:

Detailed Description

Implements unset: removes env variables.

Definition in file builtin_unset.c.

Functions

static int is_valid_unset_identifier (char *str)
 Validate an identifier for unset. More...
 
static void remove_env_node (t_env **env, char *key)
 Remove an env node by key from the doubly linked list. More...
 
int builtin_unset (char **args, t_env **env)
 Implement the unset command. More...
 

Function Documentation

◆ is_valid_unset_identifier()

static int is_valid_unset_identifier ( char *  str)
static

Validate an identifier for unset.

Must start with alpha or _ followed by alnum or _ only

Parameters
strString to validate
Returns
1 if valid and 0 if not

Definition at line 24 of file builtin_unset.c.

Referenced by builtin_unset().

+ Here is the caller graph for this function:

◆ remove_env_node()

static void remove_env_node ( t_env **  env,
char *  key 
)
static

Remove an env node by key from the doubly linked list.

Finds the node matching the key and unlinks it from the list + frees

Parameters
env
key

Definition at line 50 of file builtin_unset.c.

References t_env::key, t_env::next, t_env::prev, and t_env::value.

Referenced by builtin_unset().

+ Here is the caller graph for this function:

◆ builtin_unset()

int builtin_unset ( char **  args,
t_env **  env 
)

Implement the unset command.

Remove named variables from environment

  • Invalid identifiers are skipped (silently)
  • Options (starting with -) return error 2
Parameters
argsNULL terminated arg array with arg[0] = "unset"
envPointer to env list head (nodes will be removed)
Returns
0 on success and 2 if an invalid option was given

Definition at line 86 of file builtin_unset.c.

References is_valid_unset_identifier(), and remove_env_node().

Referenced by exec_builtin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Go to the source code of this file.