MiniDevil As beautiful as a shell
builtin_export.c File Reference

Implements export: sets and displays env variables. More...

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

Detailed Description

Implements export: sets and displays env variables.

Definition in file builtin_export.c.

Functions

static int is_valid_identifier (char *str)
 Validate an export identifier (KEY or KEY= or KEY+=) More...
 
static void print_export_error (char *arg)
 Print export error. More...
 
static int export_one (char *arg, t_env **env)
 Process an export argument. More...
 
int builtin_export (char **args, t_env **env)
 Implement the export command. More...
 

Function Documentation

◆ is_valid_identifier()

static int is_valid_identifier ( char *  str)
static

Validate an export identifier (KEY or KEY= or KEY+=)

  • Must start with alpha or _, followed by alnum or _
  • A + is allowed only immediately right before =
Parameters
strString to validate
Returns
1 if valid and 0 otherwise

Definition at line 26 of file builtin_export.c.

Referenced by export_one().

+ Here is the caller graph for this function:

◆ print_export_error()

static void print_export_error ( char *  arg)
static

Print export error.

Parameters
argThe invalid argument string

Definition at line 56 of file builtin_export.c.

Referenced by export_one().

+ Here is the caller graph for this function:

◆ export_one()

static int export_one ( char *  arg,
t_env **  env 
)
static

Process an export argument.

Parameters
argArgument string (KEY=value, KEY+=value or KEY)
envPointer to env list head
Returns
0 on success and 1 or 2 on error

Definition at line 70 of file builtin_export.c.

References export_append(), export_assign(), export_no_value(), is_valid_identifier(), and print_export_error().

Referenced by builtin_export().

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

◆ builtin_export()

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

Implement the export command.

  • With no arguments it prints all env vars sorted by alphabetical order in "declare -x" format
  • With arguments it exports each 1 (support for =, += and no value formats)
Parameters
argsNULL terminated arg array with arg[0] = "export"
envPointer to env list head (modified on export)
Returns
0 on success or highest error code from the processed args

Definition at line 99 of file builtin_export.c.

References export_one(), and print_sorted_export().

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.