Enable lc_printf and friends handling of j, t, and z length modifier.
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Thu, 6 Jan 2011 01:48:42 +0000 (01:48 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Thu, 6 Jan 2011 01:48:42 +0000 (01:48 +0000)
Add a work-around for non-C99 MSCRT.

Use ir_printf now instead of printf.

[r28212]

ir/libcore/lc_printf.c
ir/libcore/lc_printf.h
ir/libcore/lc_printf_arg_types.def

index e740c03..bfe0355 100644 (file)
@@ -172,6 +172,39 @@ static char *make_fmt(char *buf, size_t len, const lc_arg_occ_t *occ)
        strncpy(mod, occ->modifier, sizeof(mod) - 1);
        mod[LC_MIN(sizeof(mod) - 1, occ->modifier_length)] = '\0';
 
+#ifdef _MSC_VER
+       /* work-around for buggy mscrt not supporting z, j,  and t modifier */
+       if (occ->modifier_length == 1) {
+               if (mod[0] == 'z') {
+                       if (sizeof(size_t) == sizeof(int))
+                               mod[0] = '\0';
+                       if (sizeof(size_t) == sizeof(__int64)) {
+                               mod[0] = 'I';
+                               mod[1] = '6';
+                               mod[2] = '4';
+                               mod[3] = '\0';
+                       }
+               } else if (mod[0] == 't') {
+                       if (sizeof(ptrdiff_t) == sizeof(int))
+                               mod[0] = '\0';
+                       if (sizeof(ptrdiff_t) == sizeof(__int64)) {
+                               mod[0] = 'I';
+                               mod[1] = '6';
+                               mod[2] = '4';
+                               mod[3] = '\0';
+                       }
+               } else if (mod[0] == 'j') {
+                       if (sizeof(intmax_t) == sizeof(int))
+                               mod[0] = '\0';
+                       if (sizeof(intmax_t) == sizeof(__int64)) {
+                               mod[0] = 'I';
+                               mod[1] = '6';
+                               mod[2] = '4';
+                               mod[3] = '\0';
+                       }
+               }
+       }
+#endif
        snprintf(buf, len, "%%%s%s%s%s%s%s%s%s%c",
                        occ->flag_space ? "#" : "",
                        occ->flag_hash ? "#" : "",
@@ -198,11 +231,9 @@ static int std_get_lc_arg_type(const lc_arg_occ_t *occ)
                        case 'l':
                                return modlen > 1 && mod[1] == 'l' ? lc_arg_type_long_long : lc_arg_type_long;
 #define TYPE_CASE(letter,type) case letter: return lc_arg_type_ ## type;
-#if 0
                        TYPE_CASE('j', intmax_t);
                        TYPE_CASE('z', size_t);
                        TYPE_CASE('t', ptrdiff_t);
-#endif
                        TYPE_CASE('L', long_double);
 #undef TYPE_CASE
                }
index c3d0497..0d48e73 100644 (file)
  * @date 3.1.2005
  */
 
-#ifndef _LIBCORE_XPRINTF_H
-#define _LIBCORE_XPRINTF_H
+#ifndef _LIBCORE_LC_PRINTF_H
+#define _LIBCORE_LC_PRINTF_H
 
 #include <stddef.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <stdint.h>
 
 #include <obstack.h>
 
index db9b383..254d3e9 100644 (file)
@@ -4,3 +4,6 @@ LC_ARG_TYPE(LC_LONGLONG, long_long)
 LC_ARG_TYPE(double, double)
 LC_ARG_TYPE(LC_LONGDOUBLE, long_double)
 LC_ARG_TYPE(void *, ptr)
+LC_ARG_TYPE(intmax_t, intmax_t)
+LC_ARG_TYPE(ptrdiff_t, ptrdiff_t)
+LC_ARG_TYPE(size_t, size_t)