Functions | Variables
env.c File Reference
#include "orconfig.h"
#include "lib/process/env.h"
#include "lib/malloc/malloc.h"
#include "lib/ctime/di_ops.h"
#include "lib/container/smartlist.h"
#include "lib/log/util_bug.h"
#include "lib/log/log.h"
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.


char ** get_environment (void)
static size_t str_num_before (const char *s, char ch)
int environment_variable_names_equal (const char *s1, const char *s2)
void process_environment_free_ (process_environment_t *env)
process_environment_tprocess_environment_make (struct smartlist_t *env_vars)
struct smartlist_tget_current_process_environment_variables (void)
void set_environment_variable_in_smartlist (struct smartlist_t *env_vars, const char *new_var, void(*free_old)(void *), int free_p)


char ** environ

Detailed Description

Inspect and manipulate the environment variables.

Definition in file env.c.

Function Documentation

◆ environment_variable_names_equal()

int environment_variable_names_equal ( const char *  s1,
const char *  s2 

Return non-zero iff getenv would consider s1 and s2 to have the same name as strings in a process's environment.

Definition at line 71 of file env.c.

References str_num_before(), and tor_memeq().

Referenced by set_environment_variable_in_smartlist().

◆ get_current_process_environment_variables()

struct smartlist_t* get_current_process_environment_variables ( void  )

Return a newly allocated smartlist containing every variable in this process's environment, as a NUL-terminated string of the form "NAME=VALUE". Note that on some/many/most/all OSes, the parent process can put strings not of that form in our environment; callers should try to not get crashed by that.

The returned strings are heap-allocated, and must be freed by the caller.

Definition at line 190 of file env.c.

References get_environment(), and smartlist_add_strdup().

Referenced by create_managed_proxy_environment().

◆ get_environment()

char** get_environment ( void  )

Return the current environment. This is a portable replacement for 'environ'.

Definition at line 43 of file env.c.

Referenced by get_current_process_environment_variables().

◆ process_environment_free_()

void process_environment_free_ ( process_environment_t env)

Free env (assuming it was produced by process_environment_make).

Definition at line 83 of file env.c.

References tor_free, process_environment_t::unixoid_environment_block, and process_environment_t::windows_environment_block.

◆ process_environment_make()

process_environment_t* process_environment_make ( struct smartlist_t env_vars)

Make a process_environment_t containing the environment variables specified in env_vars (as C strings of the form "NAME=VALUE").

Definition at line 102 of file env.c.

Referenced by process_get_environment().

◆ set_environment_variable_in_smartlist()

void set_environment_variable_in_smartlist ( struct smartlist_t env_vars,
const char *  new_var,
void(*)(void *)  free_old,
int  free_p 

For each string s in env_vars such that environment_variable_names_equal(s, new_var), remove it; if free_p is non-zero, call free_old(s). If new_var contains '=', insert it into env_vars.

Definition at line 207 of file env.c.

References environment_variable_names_equal(), SMARTLIST_DEL_CURRENT, and SMARTLIST_FOREACH_BEGIN.

◆ str_num_before()

static size_t str_num_before ( const char *  s,
char  ch 

Helper: return the number of characters in s preceding the first occurrence of ch. If ch does not occur in s, return the length of s. Should be equivalent to strspn(s, "ch").

Definition at line 59 of file env.c.

Referenced by environment_variable_names_equal().