Index: php4srb/configure.in =================================================================== RCS file: /repository/php4/configure.in,v retrieving revision 1.210 diff -u -u -r1.210 configure.in --- php4srb/configure.in 2001/01/13 11:48:47 1.210 +++ php4srb/configure.in 2001/01/14 03:05:05 @@ -366,6 +366,7 @@ inet_aton \ isascii \ link \ +localeconv \ localtime_r \ lockf \ lrand48 \ Index: php4srb/ext/standard/basic_functions.c =================================================================== RCS file: /repository/php4/ext/standard/basic_functions.c,v retrieving revision 1.296 diff -u -u -r1.296 basic_functions.c --- php4srb/ext/standard/basic_functions.c 2001/01/13 23:49:44 1.296 +++ php4srb/ext/standard/basic_functions.c 2001/01/14 03:05:08 @@ -182,6 +182,7 @@ PHP_FE(explode, NULL) PHP_FE(implode, NULL) PHP_FE(setlocale, NULL) + PHP_FE(localeconv, NULL) PHP_FE(soundex, NULL) PHP_FE(levenshtein, NULL) PHP_FE(chr, NULL) @@ -713,6 +714,9 @@ PHP_MINIT(pack)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(browscap)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(lcg)(INIT_FUNC_ARGS_PASSTHRU); +#ifdef ZTS + PHP_MINIT(localeconv)(INIT_FUNC_ARGS_PASSTHRU); +#endif #if HAVE_CRYPT PHP_MINIT(crypt)(INIT_FUNC_ARGS_PASSTHRU); @@ -769,6 +773,9 @@ PHP_MSHUTDOWN(url_scanner_ex)(SHUTDOWN_FUNC_ARGS_PASSTHRU); #endif PHP_MSHUTDOWN(file)(SHUTDOWN_FUNC_ARGS_PASSTHRU); +#ifdef ZTS + PHP_MSHUTDOWN(localeconv)(SHUTDOWN_FUNC_ARGS_PASSTHRU); +#endif return SUCCESS; } Index: php4srb/ext/standard/php_string.h =================================================================== RCS file: /repository/php4/ext/standard/php_string.h,v retrieving revision 1.31 diff -u -u -r1.31 php_string.h --- php4srb/ext/standard/php_string.h 2001/01/09 15:11:23 1.31 +++ php4srb/ext/standard/php_string.h 2001/01/14 03:05:08 @@ -65,6 +65,7 @@ PHP_FUNCTION(ord); PHP_FUNCTION(nl2br); PHP_FUNCTION(setlocale); +PHP_FUNCTION(localeconv); PHP_FUNCTION(stristr); PHP_FUNCTION(chunk_split); PHP_FUNCTION(parse_str); Index: php4srb/ext/standard/string.c =================================================================== RCS file: /repository/php4/ext/standard/string.c,v retrieving revision 1.182 diff -u -u -r1.182 string.c --- php4srb/ext/standard/string.c 2001/01/09 15:11:23 1.182 +++ php4srb/ext/standard/string.c 2001/01/14 03:05:10 @@ -36,6 +36,9 @@ #include "php_globals.h" #include "basic_functions.h" #include "php_smart_str.h" +#ifdef ZTS +#include "TSRM.h" +#endif #define STR_PAD_LEFT 0 #define STR_PAD_RIGHT 1 @@ -53,6 +56,17 @@ REGISTER_LONG_CONSTANT("PATHINFO_BASENAME", PHP_PATHINFO_BASENAME, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PATHINFO_EXTENSION", PHP_PATHINFO_EXTENSION, CONST_CS | CONST_PERSISTENT); +#ifdef HAVE_LOCALECONV + /* If last members of struct lconv equal CHAR_MAX, no grouping is done */ + +/* This is bad, but since we are going to be hardcoding in the POSIX stuff anyway... */ +# ifndef HAVE_LIMITS_H +# define CHAR_MAX 127 +# endif + + REGISTER_LONG_CONSTANT("CHAR_MAX", CHAR_MAX, CONST_CS | CONST_PERSISTENT); +#endif + #ifdef HAVE_LOCALE_H REGISTER_LONG_CONSTANT("LC_CTYPE", LC_CTYPE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("LC_NUMERIC", LC_NUMERIC, CONST_CS | CONST_PERSISTENT); @@ -72,6 +86,11 @@ /* this is read-only, so it's ok */ static char hexconvtab[] = "0123456789abcdef"; +/* localeconv mutex */ +#ifdef ZTS +static MUTEX_T locale_mutex = NULL; +#endif + static char *php_bin2hex(const unsigned char *old, const size_t oldlen, size_t *newlen) { unsigned char *result = NULL; @@ -92,6 +111,47 @@ return result; } +#ifdef HAVE_LOCALECONV +/* glibc's localeconv is not reentrant, so lets make it so ... sorta */ +struct lconv *localeconv_r(struct lconv *out) +{ + struct lconv *res; + +# ifdef ZTS + tsrm_mutex_lock( locale_mutex ); +# endif + + /* localeconv doesn't return an error condition */ + res = localeconv(); + + *out = *res; + +# ifdef ZTS + tsrm_mutex_unlock( locale_mutex ); +# endif + + return out; +} + +# ifdef ZTS +PHP_MINIT_FUNCTION(localeconv) +{ + locale_mutex = tsrm_mutex_alloc(); + + return SUCCESS; +} + +PHP_MSHUTDOWN_FUNCTION(localeconv) +{ + tsrm_mutex_free( locale_mutex ); + + locale_mutex = NULL; + + return SUCCESS; +} +# endif +#endif + /* {{{ proto string bin2hex(string data) Converts the binary representation of data to hex */ PHP_FUNCTION(bin2hex) @@ -2424,6 +2484,96 @@ RETURN_FALSE; } /* }}} */ + +/* {{{ proto array localeconv( void ) + Returns all the information stored in the lconv struct defined + in locale.h based on the currently selected locale */ +PHP_FUNCTION(localeconv) +{ + zval *grouping, *mon_grouping; + int len, i; + + MAKE_STD_ZVAL(grouping); + MAKE_STD_ZVAL(mon_grouping); + + /* We don't need no stinkin' parameters... */ + if (ZEND_NUM_ARGS() > 0) { + WRONG_PARAM_COUNT; + } + + if (array_init(return_value) == FAILURE) { + RETURN_FALSE; + } + + if (array_init(grouping) == FAILURE || array_init(mon_grouping) == FAILURE) { + RETURN_FALSE; + } + +#ifdef HAVE_LOCALECONV + { + struct lconv currlocdata; + + localeconv_r( &currlocdata ); + + /* Grab the grouping data out of the array */ + len = strlen(currlocdata.grouping); + + for (i=0;ivalue.ht, "grouping", 9, &grouping, sizeof(zval *), NULL); + zend_hash_update(return_value->value.ht, "mon_grouping", 13, &mon_grouping, sizeof(zval *), NULL); +} /* {{{ proto void parse_str(string encoded_string, [array result]) Parses GET/POST/COOKIE data and sets global variables */