25 #ifdef HAVE_CRT_EXTERNS_H
27 #include <crt_externs.h>
30 #ifndef HAVE__NSGETENVIRON
31 #ifndef HAVE_EXTERN_ENVIRON_DECLARED
33 #ifndef RUNNING_DOXYGEN
34 extern char **environ;
44 #ifdef HAVE__NSGETENVIRON
48 return *_NSGetEnviron();
60 const char *cp = strchr(s, ch);
75 return (s1_name_len == s2_name_len &&
84 if (env == NULL)
return;
104 int n_env_vars = smartlist_len(env_vars);
106 size_t total_env_length;
114 total_env_length = 1;
115 for (i = 0; i < n_env_vars; ++i) {
116 const char *s = smartlist_get(env_vars, (
int)i);
117 size_t slen = strlen(s);
120 tor_assert(slen + 1 < SIZE_MAX - total_env_length);
121 total_env_length += slen + 1;
143 const char *prev_env_var = NULL;
145 for (i = 0; i < n_env_vars; ++i) {
146 const char *s = smartlist_get(env_vars_sorted, (
int)i);
147 size_t slen = strlen(s);
150 if (s_name_len == slen) {
152 "Preparing an environment containing a variable "
153 "without a value: %s",
156 if (prev_env_var != NULL &&
159 "Preparing an environment containing two variables "
160 "with the same name: %s and %s",
167 memcpy(cp, s, slen+1);
175 smartlist_free(env_vars_sorted);
208 void (*free_old)(
void*),
218 } SMARTLIST_FOREACH_END(s);
220 if (strchr(new_var,
'=') != NULL) {
int tor_memeq(const void *a, const void *b, size_t sz)
static size_t str_num_before(const char *s, char ch)
process_environment_t * process_environment_make(struct smartlist_t *env_vars)
int environment_variable_names_equal(const char *s1, const char *s2)
char ** get_environment(void)
struct smartlist_t * get_current_process_environment_variables(void)
void process_environment_free_(process_environment_t *env)
void set_environment_variable_in_smartlist(struct smartlist_t *env_vars, const char *new_var, void(*free_old)(void *), int free_p)
Headers for util_malloc.c.
void smartlist_sort_strings(smartlist_t *sl)
void smartlist_add_all(smartlist_t *s1, const smartlist_t *s2)
smartlist_t * smartlist_new(void)
void smartlist_add_strdup(struct smartlist_t *sl, const char *string)
void smartlist_add(smartlist_t *sl, void *element)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_DEL_CURRENT(sl, var)
char * windows_environment_block
char ** unixoid_environment_block
Macros to manage assertions, fatal and non-fatal.