From: Dmitry Stogov Date: Tue, 19 Dec 2006 13:13:48 +0000 (+0000) Subject: Support for systems without locale.h X-Git-Tag: RELEASE_1_0_0RC1~644 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fb7237eebd77e906f086bb3f5bce7b6316bdf1a7;p=php Support for systems without locale.h --- diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c index eea91efdcf..33ade0b5cf 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 f6df906d52..4c0d0db539 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 @@ -941,12 +946,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 = '-'; @@ -993,10 +1000,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 6e10e52841..c4f1e2619c 100644 --- a/main/spprintf.c +++ b/main/spprintf.c @@ -93,6 +93,9 @@ #ifdef HAVE_LOCALE_H #include +#define LCONV_DECIMAL_POINT (*lconv->decimal_point) +#else +#define LCONV_DECIMAL_POINT '.' #endif #include "snprintf.h" @@ -230,7 +233,9 @@ static void xbuf_format_converter(int unicode, smart_str *xbuf, const char *fmt, char char_buf[2]; /* for printing %% and % */ zend_bool free_s; /* free string if allocated here */ +#ifdef HAVE_LOCALE_H struct lconv *lconv = NULL; +#endif /* * Flag variables @@ -644,12 +649,14 @@ fmt_string: 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 = '-'; @@ -696,10 +703,12 @@ fmt_string: /* * * 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)