From: Antony Dovgal Date: Tue, 17 Apr 2007 20:33:45 +0000 (+0000) Subject: fix putenv("var") (i.e. unset) on BSD systems X-Git-Tag: RELEASE_1_2_0~291 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cea78baddf5f90012d4dfed2fa1e2c244fb96808;p=php 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 efc39d03dc..833b75d738 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -4443,8 +4443,15 @@ PHP_FUNCTION(putenv) * We try to avoid this by setting our own value first */ SetEnvironmentVariable(pe.key, "bugbug"); #endif - - if (putenv(pe.putenv_string) == 0) { /* success */ + +#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..730375278b --- /dev/null +++ b/ext/standard/tests/general_functions/putenv.phpt @@ -0,0 +1,37 @@ +--TEST-- +putenv() basic tests +--FILE-- + +--EXPECTF-- +bool(false) +bool(true) +string(5) "value" +bool(true) +string(0) "" +bool(true) +bool(false) +Done +--UEXPECTF-- +bool(false) +bool(true) +unicode(5) "value" +bool(true) +unicode(0) "" +bool(true) +bool(false) +Done