aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd/mk/unix.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/cmd/mk/unix.c b/src/cmd/mk/unix.c
index 37f05b71..66bdb1ff 100644
--- a/src/cmd/mk/unix.c
+++ b/src/cmd/mk/unix.c
@@ -53,20 +53,26 @@ readenv(void)
void
exportenv(Envy *e, Shell *sh)
{
- int i;
+ int w, n;
char **p;
+ Envy *e1;
static char buf[16384];
- p = 0;
- for(i = 0; e->name; e++, i++) {
- p = (char**) Realloc(p, (i+2)*sizeof(char*));
+ n = 0;
+ for(e1 = e; e1->name; e1++)
+ n++;
+ p = Malloc((n+1)*sizeof(char*));
+ w = 0;
+ for(; e->name; e++) {
+ if(sh == &rcshell && (e->values == 0 || e->values->s == 0 || e->values->s[0] == 0))
+ continue; /* do not write empty string for empty list */
if(e->values)
snprint(buf, sizeof buf, "%s=%s", e->name, wtos(e->values, sh->iws));
else
snprint(buf, sizeof buf, "%s=", e->name);
- p[i] = strdup(buf);
+ p[w++] = strdup(buf);
}
- p[i] = 0;
+ p[w] = 0;
environ = p;
}