]> granicus.if.org Git - php/commitdiff
fix putenv("var") (i.e. unset) on BSD systems
authorAntony Dovgal <tony2001@php.net>
Tue, 17 Apr 2007 20:33:45 +0000 (20:33 +0000)
committerAntony Dovgal <tony2001@php.net>
Tue, 17 Apr 2007 20:33:45 +0000 (20:33 +0000)
add test

ext/standard/basic_functions.c
ext/standard/tests/general_functions/putenv.phpt [new file with mode: 0644]

index efc39d03dc97cb0106db74c501c2fc2cfcc62253..833b75d738f177a7d305d41d7628309a3fd4dbd8 100644 (file)
@@ -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 (file)
index 0000000..7303752
--- /dev/null
@@ -0,0 +1,37 @@
+--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
+--UEXPECTF--
+bool(false)
+bool(true)
+unicode(5) "value"
+bool(true)
+unicode(0) ""
+bool(true)
+bool(false)
+Done