MentOS  0.8.0
The Mentoring Operating System
Functions | Variables
setenv.c File Reference

Defines the functions used to manipulate the environmental variables. More...

Functions

static int __find_entry (const char *name, const size_t name_len)
 Finds the entry in the environ. More...
 
static void __clone_environ (void)
 Makes a clone of the current environ.
 
int setenv (const char *name, const char *value, int replace)
 Tries to adds the variable to the environment. More...
 
int unsetenv (const char *name)
 Tries to remove the variable from the environment. More...
 
char * getenv (const char *name)
 Returns the value of the given variable. More...
 

Variables

char ** environ
 Reference to the environ variable in setenv.c.
 
static char ** __environ = NULL
 Global environ list.
 
static size_t __environ_size = 0
 Size of the global environ list.
 

Detailed Description

Defines the functions used to manipulate the environmental variables.

Function Documentation

◆ __find_entry()

static int __find_entry ( const char *  name,
const size_t  name_len 
)
inlinestatic

Finds the entry in the environ.

Parameters
namethe name of the entry we are looking for.
name_lenthe length of the name we received.
Returns
the index of the entry, or -1 if we did not find it.

◆ getenv()

char* getenv ( const char *  name)

Returns the value of the given variable.

Parameters
nameName of the variable.
Returns
A pointer to the value, or NULL if there is no match.

◆ setenv()

int setenv ( const char *  name,
const char *  value,
int  overwrite 
)

Tries to adds the variable to the environment.

Parameters
nameName of the variable.
valueValue of the variable.
overwriteOverride existing variable value or not.
Returns
Zero on success, or -1 on error with errno indicating the cause.

◆ unsetenv()

int unsetenv ( const char *  name)

Tries to remove the variable from the environment.

Parameters
nameName of the variable.
Returns
Zero on success, or -1 on error with errno indicating the cause.