mirror of
https://github.com/php/php-src.git
synced 2026-04-26 09:28:21 +02:00
(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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
#ifndef THREAD_SAFE
|
||||
extern char *strtok_string;
|
||||
extern char *locale_string;
|
||||
#endif
|
||||
|
||||
PHP_FUNCTION(strspn);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user