From 5d8183f0b22e72ce8fc3cb632ecfd253a634c6c3 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 19 Dec 2006 13:13:29 +0000 Subject: [PATCH] Support for systems without locale.h --- ext/standard/formatted_print.c | 13 +++++++++++-- main/snprintf.c | 13 +++++++++++-- main/spprintf.c | 9 +++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c index bdc9ddb325..8add3bbddf 100644 --- a/ext/standard/formatted_print.c +++ b/ext/standard/formatted_print.c @@ -27,6 +27,9 @@ #ifdef HAVE_LOCALE_H #include +#define LCONV_DECIMAL_POINT (*lconv->decimal_point) +#else +#define LCONV_DECIMAL_POINT '.' #endif #define ALIGN_LEFT 0 @@ -198,7 +201,9 @@ php_sprintf_appenddouble(char **buffer, int *pos, char num_buf[NUM_BUF_SIZE]; char *s = NULL; int s_len = 0, is_negative = 0; +#ifdef HAVE_LOCALE_H struct lconv *lconv; +#endif PRINTF_DEBUG(("sprintf: appenddouble(%x, %x, %x, %f, %d, '%c', %d, %c)\n", *buffer, pos, size, number, width, padding, alignment, fmt)); @@ -230,9 +235,11 @@ php_sprintf_appenddouble(char **buffer, int *pos, case 'E': case 'f': case 'F': +#ifdef HAVE_LOCALE_H lconv = localeconv(); +#endif s = php_conv_fp((fmt == 'f')?'F':fmt, number, 0, precision, - (fmt == 'f')?(*lconv->decimal_point):'.', + (fmt == 'f')?LCONV_DECIMAL_POINT:'.', &is_negative, &num_buf[1], &s_len); if (is_negative) { num_buf[0] = '-'; @@ -252,8 +259,10 @@ php_sprintf_appenddouble(char **buffer, int *pos, /* * * We use &num_buf[ 1 ], so that we have room for the sign */ +#ifdef HAVE_LOCALE_H lconv = localeconv(); - s = php_gcvt(number, precision, *lconv->decimal_point, (fmt == 'G')?'E':'e', &num_buf[1]); +#endif + s = php_gcvt(number, precision, LCONV_DECIMAL_POINT, (fmt == 'G')?'E':'e', &num_buf[1]); is_negative = 0; if (*s == '-') { is_negative = 1; diff --git a/main/snprintf.c b/main/snprintf.c index 6f07022383..f3f6dae90b 100644 --- a/main/snprintf.c +++ b/main/snprintf.c @@ -38,6 +38,9 @@ #ifdef HAVE_LOCALE_H #include +#define LCONV_DECIMAL_POINT (*lconv->decimal_point) +#else +#define LCONV_DECIMAL_POINT '.' #endif /* @@ -584,7 +587,9 @@ static int format_converter(register buffy * odp, const char *fmt, char num_buf[NUM_BUF_SIZE]; char char_buf[2]; /* for printing %% and % */ +#ifdef HAVE_LOCALE_H struct lconv *lconv = NULL; +#endif /* * Flag variables @@ -942,12 +947,14 @@ static int format_converter(register buffy * odp, const char *fmt, s = "inf"; s_len = 3; } else { +#ifdef HAVE_LOCALE_H if (!lconv) { lconv = localeconv(); } +#endif s = php_conv_fp((*fmt == 'f')?'F':*fmt, fp_num, alternate_form, (adjust_precision == NO) ? FLOAT_DIGITS : precision, - (*fmt == 'f')?(*lconv->decimal_point):'.', + (*fmt == 'f')?LCONV_DECIMAL_POINT:'.', &is_negative, &num_buf[1], &s_len); if (is_negative) prefix_char = '-'; @@ -994,10 +1001,12 @@ static int format_converter(register buffy * odp, const char *fmt, /* * * We use &num_buf[ 1 ], so that we have room for the sign */ +#ifdef HAVE_LOCALE_H if (!lconv) { lconv = localeconv(); } - s = php_gcvt(fp_num, precision, *lconv->decimal_point, (*fmt == 'G')?'E':'e', &num_buf[1]); +#endif + s = php_gcvt(fp_num, precision, LCONV_DECIMAL_POINT, (*fmt == 'G')?'E':'e', &num_buf[1]); if (*s == '-') prefix_char = *s++; else if (print_sign) diff --git a/main/spprintf.c b/main/spprintf.c index a0d499fdf2..60c2f1b886 100644 --- a/main/spprintf.c +++ b/main/spprintf.c @@ -92,6 +92,9 @@ #ifdef HAVE_LOCALE_H #include +#define LCONV_DECIMAL_POINT (*lconv->decimal_point) +#else +#define LCONV_DECIMAL_POINT '.' #endif #include "snprintf.h" @@ -199,7 +202,9 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) char num_buf[NUM_BUF_SIZE]; char char_buf[2]; /* for printing %% and % */ +#ifdef HAVE_LOCALE_H struct lconv *lconv = NULL; +#endif /* * Flag variables @@ -554,9 +559,11 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) s = "inf"; s_len = 3; } else { +#ifdef HAVE_LOCALE_H if (!lconv) { lconv = localeconv(); } +#endif s = php_conv_fp((*fmt == 'f')?'F':*fmt, fp_num, alternate_form, (adjust_precision == NO) ? FLOAT_DIGITS : precision, (*fmt == 'f')?(*lconv->decimal_point):'.', @@ -606,9 +613,11 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) /* * * We use &num_buf[ 1 ], so that we have room for the sign */ +#ifdef HAVE_LOCALE_H if (!lconv) { lconv = localeconv(); } +#endif s = php_gcvt(fp_num, precision, *lconv->decimal_point, (*fmt == 'G')?'E':'e', &num_buf[1]); if (*s == '-') prefix_char = *s++; -- 2.40.0