summaryrefslogtreecommitdiffstats
path: root/sysif.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-03-08 06:16:41 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-03-08 06:16:41 -0800
commit685786b3715e984fb37929dfac9891924f60d811 (patch)
treef5d543f87ec7ad22d5c1f7d28b6927d6d6931932 /sysif.c
parentd61e8cacdaea0235f564a7e966c5742bc1f010d8 (diff)
downloadtxr-685786b3715e984fb37929dfac9891924f60d811.tar.gz
txr-685786b3715e984fb37929dfac9891924f60d811.tar.bz2
txr-685786b3715e984fb37929dfac9891924f60d811.zip
Allow nil value in setenv.
* sysif.c (setenv_wrap): If value is nil, and overwrite is missing or t, call unsetenv. * txr.1: Documented.
Diffstat (limited to 'sysif.c')
-rw-r--r--sysif.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/sysif.c b/sysif.c
index 3b8341cc..d0a06ca0 100644
--- a/sysif.c
+++ b/sysif.c
@@ -703,8 +703,12 @@ val getenv_wrap(val name)
static val setenv_wrap(val name, val value, val overwrite)
{
char *nameu8 = utf8_dup_to(c_str(name));
- char *valu8 = utf8_dup_to(c_str(value));
- setenv(nameu8, valu8, default_arg(overwrite, t) != nil);
+ char *valu8 = value ? utf8_dup_to(c_str(value)) : 0;
+ int ovw = default_arg(overwrite, t) != nil;
+ if (valu8)
+ setenv(nameu8, valu8, ovw);
+ else if (ovw)
+ unsetenv(nameu8);
free(valu8);
free(nameu8);
return value;