]> granicus.if.org Git - php/commitdiff
(PHP setlocale) Locale settings are now correctly restored to the values
authorJouni Ahto <jah@php.net>
Fri, 8 Oct 1999 02:10:57 +0000 (02:10 +0000)
committerJouni Ahto <jah@php.net>
Fri, 8 Oct 1999 02:10:57 +0000 (02:10 +0000)
set in environment at request shutdown.
@- setlocale doesn't anymore screw up things if you forgot to change it back
   to the original settings. (Jouni)
# Trying to conform to the rules set up by Andrei. Let's hope this works.

ext/standard/basic_functions.c
ext/standard/php3_string.h
ext/standard/string.c

index f49af1860fe19894f955d7a8601e04f3f3d42cbe..c7e29b8239e325d8f35930bde44678eae31b8294 100644 (file)
@@ -36,6 +36,9 @@
 #else
 #include <strings.h>
 #endif
+#if HAVE_LOCALE_H
+#include <locale.h>
+#endif
 #include "safe_mode.h"
 #if WIN32|WINNT
 #include "win32/unistd.h"
@@ -424,6 +427,7 @@ PHP_MSHUTDOWN_FUNCTION(basic)
 PHP_RINIT_FUNCTION(basic)
 {
        strtok_string = NULL;
+       locale_string = NULL;
 #ifdef HAVE_PUTENV
        if (zend_hash_init(&putenv_ht, 1, NULL, (int (*)(void *)) _php3_putenv_destructor, 0) == FAILURE) {
                return FAILURE;
@@ -441,6 +445,12 @@ PHP_RSHUTDOWN_FUNCTION(basic)
 #ifdef HAVE_PUTENV
        zend_hash_destroy(&putenv_ht);
 #endif
+       /* Check if locale was changed and change it back
+          to the value in startup environment */
+       if (locale_string != NULL) {
+               setlocale(LC_ALL, "");
+       }
+       STR_FREE(locale_string);
 
        return SUCCESS;
 }
index 725364af6bfe9650f9d25376d51e28437ab3c668..cf85853c8ad0864f3d82911ab63e7c370b7c1d91 100644 (file)
@@ -38,6 +38,7 @@
 
 #ifndef THREAD_SAFE
 extern char *strtok_string;
+extern char *locale_string;
 #endif
 
 PHP_FUNCTION(strspn);
index 54343085fe2c8eeecaf5bb99cf2ef85cbfdbd662..19e76a14f9b8778fb8b66f12b7395ea1839f6291 100644 (file)
@@ -1795,6 +1795,10 @@ PHP_FUNCTION(strip_tags)
 }
 /* }}} */
 
+#ifndef THREAD_SAFE
+char *locale_string;
+#endif
+
 /* {{{ proto string setlocale(string category, string locale)
    Set locale information */
 PHP_FUNCTION(setlocale)
@@ -1833,6 +1837,12 @@ PHP_FUNCTION(setlocale)
                loc = locale->value.str.val;
        retval = setlocale (cat, loc);
        if (retval) {
+               /* Remember if locale was changed */
+               if (loc) {
+                       STR_FREE(locale_string);
+                       strtok_string = estrdup(retval);
+               }
+
                RETVAL_STRING(retval,1);
                return;
        }