From 16129b702441e64a53edd3ee9d4669b773e6beaa Mon Sep 17 00:00:00 2001 From: Antony Dovgal Date: Tue, 17 Apr 2007 20:34:14 +0000 Subject: [PATCH] MFH: fix putenv("var") (i.e. unset) on BSD systems add test --- ext/standard/basic_functions.c | 9 +++++- .../tests/general_functions/putenv.phpt | 28 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/general_functions/putenv.phpt 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 -- 2.50.1