From 026d92f58bec731efc2356bdc9b5851baa62bfca Mon Sep 17 00:00:00 2001 From: tobil4sk Date: Thu, 26 Aug 2021 19:31:56 +0100 Subject: [PATCH] Fix `put_env` inconsistency between platforms #229 * When `put_env` is called with an empty string for `v`, it now unsets the variable on all platforms, not just windows --- libs/std/sys.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/std/sys.c b/libs/std/sys.c index 1a7ce00e..4bbb98ec 100644 --- a/libs/std/sys.c +++ b/libs/std/sys.c @@ -96,9 +96,14 @@ static value put_env( value e, value v ) { if( putenv(val_string(buffer_to_string(b))) != 0 ) neko_error(); #else + char *val; val_check(e,string); val_check(v,string); - if( setenv(val_string(e),val_string(v),1) != 0 ) + val = val_string(v); + if( val[0] == '\0' ) { + if( unsetenv(val_string(e)) != 0 ) + neko_error(); + } else if( setenv(val_string(e),val,1) != 0 ) neko_error(); #endif return val_true;