@ -78,6 +78,8 @@ custom_env_init_from_environ(struct custom_env *env)
wl_array_init ( & env - > envp ) ;
wl_array_init ( & env - > envp ) ;
env - > env_finalized = false ;
env - > env_finalized = false ;
wl_array_init ( & env - > argp ) ;
env - > arg_finalized = false ;
for ( it = environ ; * it ; it + + ) {
for ( it = environ ; * it ; it + + ) {
ep = wl_array_add ( & env - > envp , sizeof * ep ) ;
ep = wl_array_add ( & env - > envp , sizeof * ep ) ;
@ -94,8 +96,11 @@ custom_env_fini(struct custom_env *env)
wl_array_for_each ( p , & env - > envp )
wl_array_for_each ( p , & env - > envp )
free ( * p ) ;
free ( * p ) ;
wl_array_release ( & env - > envp ) ;
wl_array_release ( & env - > envp ) ;
wl_array_for_each ( p , & env - > argp )
free ( * p ) ;
wl_array_release ( & env - > argp ) ;
}
}
static char * *
static char * *
@ -116,6 +121,20 @@ custom_env_get_env_var(struct custom_env *env, const char *name)
return NULL ;
return NULL ;
}
}
void
custom_env_add_arg ( struct custom_env * env , const char * arg )
{
char * * ap ;
assert ( ! env - > arg_finalized ) ;
ap = wl_array_add ( & env - > argp , sizeof * ap ) ;
assert ( ap ) ;
* ap = strdup ( arg ) ;
assert ( * ap ) ;
}
void
void
custom_env_set_env_var ( 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 )
{
{
@ -151,3 +170,20 @@ custom_env_get_envp(struct custom_env *env)
return env - > envp . data ;
return env - > envp . data ;
}
}
char * const *
custom_env_get_argp ( struct custom_env * env )
{
char * * ap ;
assert ( ! env - > arg_finalized ) ;
/* add terminating NULL */
ap = wl_array_add ( & env - > argp , sizeof * ap ) ;
assert ( ap ) ;
* ap = NULL ;
env - > arg_finalized = true ;
return env - > argp . data ;
}