From efdde5efe51f4221779a847e813bea9cdce73084 Mon Sep 17 00:00:00 2001 From: Hartmut Holzgraefe Date: Mon, 17 Jun 2002 11:50:25 +0000 Subject: [PATCH] making printf/sprintf locale-aware without external dependencies --- ext/standard/formatted_print.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c index 7a11b3a5f0..b2dc5cb700 100644 --- a/ext/standard/formatted_print.c +++ b/ext/standard/formatted_print.c @@ -25,6 +25,10 @@ #include "zend_execute.h" #include +#ifdef HAVE_LOCALE_H +#include +#endif + #define ALIGN_LEFT 0 #define ALIGN_RIGHT 1 #define ADJ_WIDTH 1 @@ -274,6 +278,14 @@ 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 PRINTF_DEBUG(("sprintf: appenddouble(%x, %x, %x, %f, %d, '%c', %d, %c)\n", *buffer, pos, size, number, width, padding, alignment, fmt)); @@ -308,7 +320,7 @@ php_sprintf_appenddouble(char **buffer, int *pos, numbuf[i++] = '0'; if (precision > 0) { int k = precision; - numbuf[i++] = '.'; + numbuf[i++] = decimal_point; while ((decpt++ < 0) && k--) { numbuf[i++] = '0'; } @@ -317,12 +329,12 @@ php_sprintf_appenddouble(char **buffer, int *pos, while (decpt-- > 0) numbuf[i++] = cvt[j++]; if (precision > 0) - numbuf[i++] = '.'; + numbuf[i++] = decimal_point; } } else { numbuf[i++] = cvt[j++]; if (precision > 0) - numbuf[i++] = '.'; + numbuf[i++] = decimal_point; } while (cvt[j]) { -- 2.50.1