]> granicus.if.org Git - php/commitdiff
Support for systems without locale.h
authorDmitry Stogov <dmitry@php.net>
Tue, 19 Dec 2006 13:13:29 +0000 (13:13 +0000)
committerDmitry Stogov <dmitry@php.net>
Tue, 19 Dec 2006 13:13:29 +0000 (13:13 +0000)
ext/standard/formatted_print.c
main/snprintf.c
main/spprintf.c

index bdc9ddb3254d8855a74df8bbd0861f06a0cf20ce..8add3bbddf66d0110cd398c3ec6ecfbaad06bb42 100644 (file)
@@ -27,6 +27,9 @@
 
 #ifdef HAVE_LOCALE_H
 #include <locale.h>
+#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;
index 6f07022383df9082d9fe0a5cf90df5fb929199ac..f3f6dae90bb92428150f91837768a53551ebc95e 100644 (file)
@@ -38,6 +38,9 @@
 
 #ifdef HAVE_LOCALE_H
 #include <locale.h>
+#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 %<unknown> */
 
+#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)
index a0d499fdf2f29b5d61404a2746032de50df130b3..60c2f1b8862c7a5129cd47cbc6e23c0698273669 100644 (file)
@@ -92,6 +92,9 @@
 
 #ifdef HAVE_LOCALE_H
 #include <locale.h>
+#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 %<unknown> */
 
+#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++;