summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2002-10-10 16:29:35 +0000
committerIlia Alshanetsky <iliaa@php.net>2002-10-10 16:29:35 +0000
commitbc14a6f1338891d7f8f169895d2913293dc61188 (patch)
tree896fd8220202fa4f4ef8b2407595a17375df24a0 /ext
parentb5676a5b3e7d0cf468d3d3241b26cb95cf19fbd1 (diff)
downloadphp-git-bc14a6f1338891d7f8f169895d2913293dc61188.tar.gz
This patch fixes handling of floats on locales where decimal point is not a
'.'. Problem is best demonstrated by bug #17079.
Diffstat (limited to 'ext')
-rw-r--r--ext/standard/formatted_print.c12
-rw-r--r--ext/standard/string.c13
2 files changed, 15 insertions, 10 deletions
diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c
index a80913d85f..38f4e2c21c 100644
--- a/ext/standard/formatted_print.c
+++ b/ext/standard/formatted_print.c
@@ -284,14 +284,7 @@ php_sprintf_appenddouble(char **buffer, int *pos,
char *cvt;
register int i = 0, j = 0;
int sign, decpt;
- char decimal_point = '.';
-#ifdef HAVE_LOCALECONV
- struct lconv l;
-
- localeconv_r(&l);
-
- decimal_point = l.decimal_point[0];
-#endif
+ char decimal_point = EG(float_separator)[0];
PRINTF_DEBUG(("sprintf: appenddouble(%x, %x, %x, %f, %d, '%c', %d, %c)\n",
*buffer, pos, size, number, width, padding, alignment, fmt));
@@ -611,14 +604,13 @@ php_formatted_print(int ht, int *len, int use_array TSRMLS_DC)
case 'e':
case 'f':
/* XXX not done */
- convert_to_double_ex(args[argnum]);
php_sprintf_appenddouble(&result, &outpos, &size,
Z_DVAL_PP(args[argnum]),
width, padding, alignment,
precision, adjusting,
format[inpos], always_sign);
break;
-
+
case 'c':
convert_to_long_ex(args[argnum]);
php_sprintf_appendchar(&result, &outpos, &size,
diff --git a/ext/standard/string.c b/ext/standard/string.c
index c795394fdf..933b09587f 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -3216,6 +3216,19 @@ PHP_FUNCTION(setlocale)
efree(args);
RETVAL_STRING(retval, 1);
+
+ if (cat == LC_NUMERIC || cat == LC_ALL) {
+ struct lconv *lc;
+ lc = localeconv();
+
+ EG(float_separator)[0] = (lc->decimal_point)[0];
+
+ if ((lc->decimal_point)[0] != '.') {
+ /* set locale back to C */
+ setlocale(LC_NUMERIC, "C");
+ }
+ }
+
return;
}