2 * $Id: env.c,v 1.1 2002/01/22 16:03:02 dfs Exp $
4 * Copyright (C) 1995,1996,1997 Lars Fenneberg
6 * See the file COPYRIGHT for the respective terms and conditions.
7 * If the file is missing contact me at lf@elemental.net
8 * and I'll send you a copy.
14 #include <radiusclient.h>
17 * Function: rc_new_env
19 * Purpose: allocate space for a new environment
23 ENV *rc_new_env(int size)
30 if ((p = malloc(sizeof(*p))) == NULL)
33 if ((p->env = malloc(size * sizeof(char *))) == NULL)
35 rc_log(LOG_CRIT, "rc_new_env: out of memory");
49 * Function: rc_free_env
51 * Purpose: free the space used by an env structure
55 void rc_free_env(ENV *env)
62 * Function: rc_add_env
64 * Purpose: add an environment entry
68 int rc_add_env(ENV *env, char *name, char *value)
73 for (i = 0; env->env[i] != NULL; i++)
75 if (strncmp(env->env[i], name, MAX(strchr(env->env[i], '=') - env->env[i],strlen(name))) == 0)
81 if ((new_env = realloc(env->env[i], strlen(name)+strlen(value)+2)) == NULL)
84 env->env[i] = new_env;
86 sprintf(env->env[i],"%s=%s", name, value);
88 if (env->size == (env->maxsize-1)) {
89 rc_log(LOG_CRIT, "rc_add_env: not enough space for environment (increase ENV_SIZE)");
93 if ((env->env[env->size] = malloc(strlen(name)+strlen(value)+2)) == NULL) {
94 rc_log(LOG_CRIT, "rc_add_env: out of memory");
98 sprintf(env->env[env->size],"%s=%s", name, value);
102 env->env[env->size] = NULL;
109 * Function: rc_import_env
111 * Purpose: imports an array of null-terminated strings
115 int rc_import_env(ENV *env, char **import)
121 es = strchr(*import, '=');
129 /* ok, i grant thats not very clean... */
132 if (rc_add_env(env, *import, es+1) < 0)