@ -76,11 +76,11 @@ custom_env_init_from_environ(struct custom_env *env)
char * * it ;
char * * it ;
char * * ep ;
char * * ep ;
wl_array_init ( & env - > p ) ;
wl_array_init ( & env - > env p) ;
env - > finalized = false ;
env - > env_ finalized = false ;
for ( it = environ ; * it ; it + + ) {
for ( it = environ ; * it ; it + + ) {
ep = wl_array_add ( & env - > p , sizeof * ep ) ;
ep = wl_array_add ( & env - > env p, sizeof * ep ) ;
assert ( ep ) ;
assert ( ep ) ;
* ep = strdup ( * it ) ;
* ep = strdup ( * it ) ;
assert ( * ep ) ;
assert ( * ep ) ;
@ -90,21 +90,21 @@ custom_env_init_from_environ(struct custom_env *env)
void
void
custom_env_fini ( struct custom_env * env )
custom_env_fini ( struct custom_env * env )
{
{
char * * e p;
char * * p ;
wl_array_for_each ( e p, & env - > p )
wl_array_for_each ( p , & env - > env p)
free ( * e p) ;
free ( * p ) ;
wl_array_release ( & env - > p ) ;
wl_array_release ( & env - > env p) ;
}
}
static char * *
static char * *
custom_env_find_element ( struct custom_env * env , const char * name )
custom_env_get_env_var ( struct custom_env * env , const char * name )
{
{
char * * ep ;
char * * ep ;
size_t name_len = strlen ( name ) ;
size_t name_len = strlen ( name ) ;
wl_array_for_each ( ep , & env - > p ) {
wl_array_for_each ( ep , & env - > env p) {
char * entry = * ep ;
char * entry = * ep ;
if ( strncmp ( entry , name , name_len ) = = 0 & &
if ( strncmp ( entry , name , name_len ) = = 0 & &
@ -117,18 +117,18 @@ custom_env_find_element(struct custom_env *env, const char *name)
}
}
void
void
custom_env_set ( struct custom_env * env , const char * name , const char * value )
custom_env_set_env_var ( struct custom_env * env , const char * name , const char * value )
{
{
char * * ep ;
char * * ep ;
assert ( strchr ( name , ' = ' ) = = NULL ) ;
assert ( strchr ( name , ' = ' ) = = NULL ) ;
assert ( ! env - > finalized ) ;
assert ( ! env - > env_ finalized) ;
ep = custom_env_find_element ( env , name ) ;
ep = custom_env_get_env_var ( env , name ) ;
if ( ep )
if ( ep )
free ( * ep ) ;
free ( * ep ) ;
else
else
ep = wl_array_add ( & env - > p , sizeof * ep ) ;
ep = wl_array_add ( & env - > env p, sizeof * ep ) ;
assert ( ep ) ;
assert ( ep ) ;
str_printf ( ep , " %s=%s " , name , value ) ;
str_printf ( ep , " %s=%s " , name , value ) ;
@ -140,14 +140,14 @@ custom_env_get_envp(struct custom_env *env)
{
{
char * * ep ;
char * * ep ;
assert ( ! env - > finalized ) ;
assert ( ! env - > env_ finalized) ;
/* add terminating NULL */
/* add terminating NULL */
ep = wl_array_add ( & env - > p , sizeof * ep ) ;
ep = wl_array_add ( & env - > env p, sizeof * ep ) ;
assert ( ep ) ;
assert ( ep ) ;
* ep = NULL ;
* ep = NULL ;
env - > finalized = true ;
env - > env_ finalized = true ;
return env - > p . data ;
return env - > env p. data ;
}
}