MFH: fix putenv("var") (i.e. unset) on BSD systems

add test
This commit is contained in:
Antony Dovgal 2007-04-17 20:34:14 +00:00
parent 695e81c2cc
commit 16129b7024
2 changed files with 36 additions and 1 deletions

View file

@ -4461,8 +4461,15 @@ PHP_FUNCTION(putenv)
* We try to avoid this by setting our own value first */ * We try to avoid this by setting our own value first */
SetEnvironmentVariable(pe.key, "bugbug"); SetEnvironmentVariable(pe.key, "bugbug");
#endif #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 */ 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); zend_hash_add(&BG(putenv_ht), pe.key, pe.key_len+1, (void **) &pe, sizeof(putenv_entry), NULL);
#ifdef HAVE_TZSET #ifdef HAVE_TZSET
if (!strncmp(pe.key, "TZ", pe.key_len)) { if (!strncmp(pe.key, "TZ", pe.key_len)) {

View file

@ -0,0 +1,28 @@
--TEST--
putenv() basic tests
--FILE--
<?php
$var_name="SUCHVARSHOULDNOTEXIST";
var_dump(getenv($var_name));
var_dump(putenv($var_name."=value"));
var_dump(getenv($var_name));
var_dump(putenv($var_name."="));
var_dump(getenv($var_name));
var_dump(putenv($var_name));
var_dump(getenv($var_name));
echo "Done\n";
?>
--EXPECTF--
bool(false)
bool(true)
string(5) "value"
bool(true)
string(0) ""
bool(true)
bool(false)
Done