From: Antony Dovgal Date: Tue, 17 Apr 2007 20:34:14 +0000 (+0000) Subject: MFH: fix putenv("var") (i.e. unset) on BSD systems X-Git-Tag: php-5.2.2RC2~61 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=16129b702441e64a53edd3ee9d4669b773e6beaa;p=php MFH: fix putenv("var") (i.e. unset) on BSD systems add test --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index d6186e618f..5723525858 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -4461,8 +4461,15 @@ PHP_FUNCTION(putenv) * We try to avoid this by setting our own value first */ SetEnvironmentVariable(pe.key, "bugbug"); #endif - + +#if HAVE_UNSETENV + if (!p) { /* no '=' means we want to unset it */ + unsetenv(pe.putenv_string); + } + if (!p || putenv(pe.putenv_string) == 0) { /* success */ +#else if (putenv(pe.putenv_string) == 0) { /* success */ +#endif zend_hash_add(&BG(putenv_ht), pe.key, pe.key_len+1, (void **) &pe, sizeof(putenv_entry), NULL); #ifdef HAVE_TZSET if (!strncmp(pe.key, "TZ", pe.key_len)) { diff --git a/ext/standard/tests/general_functions/putenv.phpt b/ext/standard/tests/general_functions/putenv.phpt new file mode 100644 index 0000000000..afe1badce4 --- /dev/null +++ b/ext/standard/tests/general_functions/putenv.phpt @@ -0,0 +1,28 @@ +--TEST-- +putenv() basic tests +--FILE-- + +--EXPECTF-- +bool(false) +bool(true) +string(5) "value" +bool(true) +string(0) "" +bool(true) +bool(false) +Done