aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-06-07 08:00:32 +0300
committerSergey Poznyakoff <gray@gnu.org>2019-06-07 08:00:32 +0300
commitc33922f128403f5d05d24f19abeaad2368ce5467 (patch)
tree89ffecf0abbb4fedca962da0b79f0f850179e09f /lib
parentcc533e2c6b86b62db169f912b4e7891273061c77 (diff)
downloadpies-c33922f128403f5d05d24f19abeaad2368ce5467.tar.gz
pies-c33922f128403f5d05d24f19abeaad2368ce5467.tar.bz2
Implement additional env.eval statement
Diffstat (limited to 'lib')
-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.