| 337 | } |
| 338 | |
| 339 | environment_t *replace_env(struct hf_wrapper *list) |
| 340 | { |
| 341 | int var_cnt; |
| 342 | char **cp; |
| 343 | struct hf_wrapper *w; |
| 344 | char **new_env; |
| 345 | int i; |
| 346 | environment_t *backup_env; |
| 347 | |
| 348 | backup_env=(environment_t *)pkg_malloc(sizeof(environment_t)); |
| 349 | if (!backup_env) { |
| 350 | LM_ERR("no pkg mem for backup env\n"); |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | /* count length of current env list */ |
| 355 | var_cnt=0; |
| 356 | for (cp=environ; *cp; cp++) var_cnt++; |
| 357 | backup_env->old_cnt=var_cnt; |
| 358 | /* count length of our extensions */ |
| 359 | for(w=list;w;w=w->next_other) var_cnt++; |
| 360 | new_env=pkg_malloc((var_cnt+1)*sizeof(char *)); |
| 361 | if (!new_env) { |
| 362 | LM_ERR("no pkg mem\n"); |
| 363 | return 0; |
| 364 | } |
| 365 | /* put all var pointers into new environment */ |
| 366 | i=0; |
| 367 | for (cp=environ; *cp; cp++) { /* replicate old env */ |
| 368 | new_env[i]=*cp; |
| 369 | i++; |
| 370 | } |
| 371 | for (w=list;w;w=w->next_other) { /* append new env */ |
| 372 | new_env[i]=w->envvar; |
| 373 | i++; |
| 374 | } |
| 375 | new_env[i]=0; /* zero termination */ |
| 376 | /* install new environment */ |
| 377 | backup_env->env=environ; |
| 378 | environ=new_env; |
| 379 | /* return previous environment */ |
| 380 | return backup_env; |
| 381 | } |
| 382 | |
| 383 | void unset_env(environment_t *backup_env) |
| 384 | { |
no outgoing calls
no test coverage detected