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

index eea91efdcf122b72bc8d3de5c427737413fdf795..33ade0b5cf9196d4096893a775d8b2658d94114b 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 f6df906d5287775d2123ed34dd0a81207eaf9078..4c0d0db53951e254871f38afc4fe94a94cf4bb46 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
@@ -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)
index 6e10e528411a5b777bf9ec205ab1556624f49e1c..c4f1e2619c50232c064e1f1adf0cbe70ac604e5e 100644 (file)
@@ -93,6 +93,9 @@
 
 #ifdef HAVE_LOCALE_H
 #include <locale.h>
+#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 %<unknown> */
        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)