From 9109d8dcdd607640227cef8113ee8224f203bbed Mon Sep 17 00:00:00 2001 From: Jouni Ahto Date: Fri, 8 Oct 1999 02:10:57 +0000 Subject: [PATCH] (PHP setlocale) Locale settings are now correctly restored to the values 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 | 10 ++++++++++ ext/standard/php3_string.h | 1 + ext/standard/string.c | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index f49af1860f..c7e29b8239 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -36,6 +36,9 @@ #else #include #endif +#if HAVE_LOCALE_H +#include +#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; } diff --git a/ext/standard/php3_string.h b/ext/standard/php3_string.h index 725364af6b..cf85853c8a 100644 --- a/ext/standard/php3_string.h +++ b/ext/standard/php3_string.h @@ -38,6 +38,7 @@ #ifndef THREAD_SAFE extern char *strtok_string; +extern char *locale_string; #endif PHP_FUNCTION(strspn); diff --git a/ext/standard/string.c b/ext/standard/string.c index 54343085fe..19e76a14f9 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -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; } -- 2.40.0