summaryrefslogtreecommitdiffabout
path: root/lib/envop.c
Side-by-side diff
Diffstat (limited to 'lib/envop.c') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/envop.c51
1 files changed, 33 insertions, 18 deletions
diff --git a/lib/envop.c b/lib/envop.c
index ce24b92..93bd425 100644
--- a/lib/envop.c
+++ b/lib/envop.c
@@ -167,13 +167,15 @@ environ_set (environ_t *env, char const *name, char const *value)
char *def;
struct wordsplit ws;
- if (!name)
+ if (!value)
{
- errno = EINVAL;
- return -1;
+ if (!name)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ return environ_unset (env, name, value);
}
- if (!value)
- return environ_unset (env, name, value);
ws.ws_env = (char const **) env->env_base;
if (wordsplit (value, &ws,
@@ -191,7 +193,18 @@ environ_set (environ_t *env, char const *name, char const *value)
return -1;
}
- if (strcmp (name, ":") == 0)
+ if (ws.ws_envbuf)
+ {
+ free (env->env_base);
+ env->env_base = ws.ws_envbuf;
+ env->env_count = ws.ws_envidx;
+ env->env_max = ws.ws_envsiz;
+ ws.ws_envbuf = NULL;
+ ws.ws_envidx = 0;
+ ws.ws_envsiz = 0;
+ }
+
+ if (name == NULL || strcmp (name, ":") == 0)
{
wordsplit_free (&ws);
return 0;
@@ -334,6 +347,7 @@ envop_entry_add (struct envop_entry **head,
{
struct envop_entry *op;
size_t s;
+ char *p;
switch (code)
{
@@ -341,7 +355,7 @@ envop_entry_add (struct envop_entry **head,
break;
case envop_set:
- if (!name || !(*name == ':' || valid_envar_name (name)))
+ if (name && !(*name == ':' || valid_envar_name (name)))
{
errno = EINVAL;
return -1;
@@ -359,11 +373,9 @@ envop_entry_add (struct envop_entry **head,
s = sizeof (op[0]);
if (name)
- {
- s += strlen (name) + 1;
- if (value)
- s += strlen (value) + 1;
- }
+ s += strlen (name) + 1;
+ if (value)
+ s += strlen (value) + 1;
op = malloc (s);
if (!op)
return -1;
@@ -371,15 +383,18 @@ envop_entry_add (struct envop_entry **head,
op->code = code;
op->name = NULL;
op->value = NULL;
+
+ p = (char*)(op + 1);
if (name)
{
- op->name = (char*)(op + 1);
+ op->name = p;
strcpy (op->name, name);
- if (value)
- {
- op->value = op->name + strlen (name) + 1;
- strcpy (op->value, value);
- }
+ p += strlen (name) + 1;
+ }
+ if (value)
+ {
+ op->value = p;
+ strcpy (op->value, value);
}
envop_entry_insert (head, op);
return 0;

Return to:

Send suggestions and report system problems to the System administrator.