tmk: treat X= as empty list in rc shell - plan9port - [fork] Plan 9 from user space
HTML git clone git://src.adamsgaard.dk/plan9port
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 6c17f630901eec2a4b54b70748d7fbc9b47eecd8
DIR parent 9962d916e88f66014f1008d4356a2d395ae8d31b
HTML Author: Russ Cox <rsc@swtch.com>
Date: Mon, 13 Jan 2020 19:20:34 -0500
mk: treat X= as empty list in rc shell
This brings mk's behavior when using rc in line with Plan 9's.
The existing code is for Unix environment data structures but
also was assuming Unix shell semantics where empty and missing
variables are mostly equivalent.
The Plan 9 code (/sys/src/cmd/mk/plan9.c in the distribution)
explicitly removes /env/name (creating an empty list) when the
value is missing or an empty string.
Fixes #255.
Diffstat:
M src/cmd/mk/unix.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
---
DIR diff --git a/src/cmd/mk/unix.c b/src/cmd/mk/unix.c
t@@ -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;
}