MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / replace_env

Function replace_env

modules/exec/exec_hf.c:339–381  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337}
338
339environment_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
383void unset_env(environment_t *backup_env)
384{

Callers 3

w_execFunction · 0.85
w_async_execFunction · 0.85
set_envFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected