summary refs log tree commit diff
path: root/stdio-common
diff options
context:
space:
mode:
Diffstat (limited to 'stdio-common')
-rw-r--r--stdio-common/printf-parse.h25
-rw-r--r--stdio-common/vfprintf.c67
-rw-r--r--stdio-common/vfscanf.c28
3 files changed, 92 insertions, 28 deletions
diff --git a/stdio-common/printf-parse.h b/stdio-common/printf-parse.h
index 036b3b4dfe..61468ebdd3 100644
--- a/stdio-common/printf-parse.h
+++ b/stdio-common/printf-parse.h
@@ -19,8 +19,9 @@
 
 #include <ctype.h>
 #include <printf.h>
-#include <string.h>
+#include <stdint.h>
 #include <stddef.h>
+#include <string.h>
 
 #define NDEBUG 1
 #include <assert.h>
@@ -271,7 +272,8 @@ parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
   spec->info.is_char = 0;
 
   if (*format == L_('h') || *format == L_('l') || *format == L_('L') ||
-      *format == L_('Z') || *format == L_('q'))
+      *format == L_('Z') || *format == L_('q') || *format == L_('z') ||
+      *format == L_('t') || *format == L_('j'))
     switch (*format++)
       {
       case L_('h'):
@@ -297,11 +299,24 @@ parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
 	/* 4.4 uses this for long long.  */
 	spec->info.is_long_double = 1;
 	break;
+      case L_('z'):
       case L_('Z'):
 	/* int's are size_t's.  */
-	assert (sizeof(size_t) <= sizeof(unsigned long long int));
-	spec->info.is_longlong = sizeof(size_t) > sizeof(unsigned long int);
-	spec->info.is_long = sizeof(size_t) > sizeof(unsigned int);
+	assert (sizeof (size_t) <= sizeof (unsigned long long int));
+	spec->info.is_longlong = sizeof (size_t) > sizeof (unsigned long int);
+	spec->info.is_long = sizeof (size_t) > sizeof (unsigned int);
+	break;
+      case L_('t'):
+	assert (sizeof (ptrdiff_t) <= sizeof (unsigned long long int));
+	spec->info.is_longlong = (sizeof (ptrdiff_t)
+				  > sizeof (unsigned long int));
+	spec->info.is_long = sizeof (ptrdiff_t) > sizeof (unsigned int);
+	break;
+      case L_('j'):
+	assert (sizeof (intmax_t) <= sizeof (unsigned long long int));
+	spec->info.is_longlong = (sizeof (intmax_t)
+				  > sizeof (unsigned long int));
+	spec->info.is_long = sizeof (intmax_t) > sizeof (unsigned int);
 	break;
       }
 
diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c
index a40acb75d4..a3281c2e0e 100644
--- a/stdio-common/vfprintf.c
+++ b/stdio-common/vfprintf.c
@@ -20,6 +20,7 @@
 #include <limits.h>
 #include <printf.h>
 #include <stdarg.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <wchar.h>
@@ -250,14 +251,14 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
 	       0,            0,            0,            0,
 	       0, /* 'a' */ 26,            0, /* 'c' */ 20,
     /* 'd' */ 15, /* 'e' */ 19, /* 'f' */ 19, /* 'g' */ 19,
-    /* 'h' */ 10, /* 'i' */ 15,            0,            0,
+    /* 'h' */ 10, /* 'i' */ 15, /* 'j' */ 28,            0,
     /* 'l' */ 11, /* 'm' */ 24, /* 'n' */ 23, /* 'o' */ 17,
     /* 'p' */ 22, /* 'q' */ 12,            0, /* 's' */ 21,
-	       0, /* 'u' */ 16,            0,            0,
-    /* 'x' */ 18
+    /* 't' */ 27, /* 'u' */ 16,            0,            0,
+    /* 'x' */ 18,            0, /* 'z' */ 13
   };
 
-#define NOT_IN_JUMP_RANGE(Ch) ((Ch) < ' ' || (Ch) > 'x')
+#define NOT_IN_JUMP_RANGE(Ch) ((Ch) < ' ' || (Ch) > 'z')
 #define CHAR_CLASS(Ch) (jump_table[(int) (Ch) - ' '])
 #define JUMP(ChExpr, table)						      \
       do								      \
@@ -272,7 +273,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
 
 #define STEP0_3_TABLE							      \
     /* Step 0: at the beginning.  */					      \
-    static const void *step0_jumps[27] =				      \
+    static const void *step0_jumps[29] =				      \
     {									      \
       REF (form_unknown),						      \
       REF (flag_space),		/* for ' ' */				      \
@@ -287,7 +288,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (mod_half),		/* for 'h' */				      \
       REF (mod_long),		/* for 'l' */				      \
       REF (mod_longlong),	/* for 'L', 'q' */			      \
-      REF (mod_size_t),		/* for 'Z' */				      \
+      REF (mod_size_t),		/* for 'z', 'Z' */			      \
       REF (form_percent),	/* for '%' */				      \
       REF (form_integer),	/* for 'd', 'i' */			      \
       REF (form_unsigned),	/* for 'u' */				      \
@@ -300,10 +301,12 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (form_number),	/* for 'n' */				      \
       REF (form_strerror),	/* for 'm' */				      \
       REF (form_wcharacter),	/* for 'C' */				      \
-      REF (form_floathex)	/* for 'A', 'a' */			      \
+      REF (form_floathex),	/* for 'A', 'a' */			      \
+      REF (mod_ptrdiff_t),      /* for 't' */				      \
+      REF (mod_intmax_t),       /* for 'j' */				      \
     };									      \
     /* Step 1: after processing width.  */				      \
-    static const void *step1_jumps[27] =				      \
+    static const void *step1_jumps[29] =				      \
     {									      \
       REF (form_unknown),						      \
       REF (form_unknown),	/* for ' ' */				      \
@@ -318,7 +321,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (mod_half),		/* for 'h' */				      \
       REF (mod_long),		/* for 'l' */				      \
       REF (mod_longlong),	/* for 'L', 'q' */			      \
-      REF (mod_size_t),		/* for 'Z' */				      \
+      REF (mod_size_t),		/* for 'z', 'Z' */			      \
       REF (form_percent),	/* for '%' */				      \
       REF (form_integer),	/* for 'd', 'i' */			      \
       REF (form_unsigned),	/* for 'u' */				      \
@@ -331,10 +334,12 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (form_number),	/* for 'n' */				      \
       REF (form_strerror),	/* for 'm' */				      \
       REF (form_wcharacter),	/* for 'C' */				      \
-      REF (form_floathex)	/* for 'A', 'a' */			      \
+      REF (form_floathex),	/* for 'A', 'a' */			      \
+      REF (mod_ptrdiff_t),      /* for 't' */				      \
+      REF (mod_intmax_t)        /* for 'j' */				      \
     };									      \
     /* Step 2: after processing precision.  */				      \
-    static const void *step2_jumps[27] =				      \
+    static const void *step2_jumps[29] =				      \
     {									      \
       REF (form_unknown),						      \
       REF (form_unknown),	/* for ' ' */				      \
@@ -349,7 +354,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (mod_half),		/* for 'h' */				      \
       REF (mod_long),		/* for 'l' */				      \
       REF (mod_longlong),	/* for 'L', 'q' */			      \
-      REF (mod_size_t),		/* for 'Z' */				      \
+      REF (mod_size_t),		/* for 'z', 'Z' */			      \
       REF (form_percent),	/* for '%' */				      \
       REF (form_integer),	/* for 'd', 'i' */			      \
       REF (form_unsigned),	/* for 'u' */				      \
@@ -362,10 +367,12 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (form_number),	/* for 'n' */				      \
       REF (form_strerror),	/* for 'm' */				      \
       REF (form_wcharacter),	/* for 'C' */				      \
-      REF (form_floathex)	/* for 'A', 'a' */			      \
+      REF (form_floathex),	/* for 'A', 'a' */			      \
+      REF (mod_ptrdiff_t),      /* for 't' */				      \
+      REF (mod_intmax_t)        /* for 'j' */				      \
     };									      \
     /* Step 3a: after processing first 'h' modifier.  */		      \
-    static const void *step3a_jumps[27] =				      \
+    static const void *step3a_jumps[29] =				      \
     {									      \
       REF (form_unknown),						      \
       REF (form_unknown),	/* for ' ' */				      \
@@ -380,7 +387,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (mod_halfhalf),	/* for 'h' */				      \
       REF (form_unknown),	/* for 'l' */				      \
       REF (form_unknown),	/* for 'L', 'q' */			      \
-      REF (form_unknown),	/* for 'Z' */				      \
+      REF (form_unknown),	/* for 'z', 'Z' */			      \
       REF (form_percent),	/* for '%' */				      \
       REF (form_integer),	/* for 'd', 'i' */			      \
       REF (form_unsigned),	/* for 'u' */				      \
@@ -393,10 +400,12 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (form_number),	/* for 'n' */				      \
       REF (form_unknown),	/* for 'm' */				      \
       REF (form_unknown),	/* for 'C' */				      \
-      REF (form_unknown)	/* for 'A', 'a' */			      \
+      REF (form_unknown),	/* for 'A', 'a' */			      \
+      REF (form_unknown),       /* for 't' */				      \
+      REF (form_unknown)        /* for 'j' */				      \
     };									      \
     /* Step 3b: after processing first 'l' modifier.  */		      \
-    static const void *step3b_jumps[27] =				      \
+    static const void *step3b_jumps[29] =				      \
     {									      \
       REF (form_unknown),						      \
       REF (form_unknown),	/* for ' ' */				      \
@@ -411,7 +420,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (form_unknown),	/* for 'h' */				      \
       REF (mod_longlong),	/* for 'l' */				      \
       REF (form_unknown),	/* for 'L', 'q' */			      \
-      REF (form_unknown),	/* for 'Z' */				      \
+      REF (form_unknown),	/* for 'z', 'Z' */			      \
       REF (form_percent),	/* for '%' */				      \
       REF (form_integer),	/* for 'd', 'i' */			      \
       REF (form_unsigned),	/* for 'u' */				      \
@@ -424,12 +433,14 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (form_number),	/* for 'n' */				      \
       REF (form_strerror),	/* for 'm' */				      \
       REF (form_wcharacter),	/* for 'C' */				      \
-      REF (form_floathex)	/* for 'A', 'a' */			      \
+      REF (form_floathex),	/* for 'A', 'a' */			      \
+      REF (form_unknown),       /* for 't' */				      \
+      REF (form_unknown)        /* for 'j' */				      \
     }
 
 #define STEP4_TABLE							      \
     /* Step 4: processing format specifier.  */				      \
-    static const void *step4_jumps[27] =				      \
+    static const void *step4_jumps[29] =				      \
     {									      \
       REF (form_unknown),						      \
       REF (form_unknown),	/* for ' ' */				      \
@@ -444,7 +455,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (form_unknown),	/* for 'h' */				      \
       REF (form_unknown),	/* for 'l' */				      \
       REF (form_unknown),	/* for 'L', 'q' */			      \
-      REF (form_unknown),	/* for 'Z' */				      \
+      REF (form_unknown),	/* for 'z', 'Z' */			      \
       REF (form_percent),	/* for '%' */				      \
       REF (form_integer),	/* for 'd', 'i' */			      \
       REF (form_unsigned),	/* for 'u' */				      \
@@ -457,7 +468,9 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (form_number),	/* for 'n' */				      \
       REF (form_strerror),	/* for 'm' */				      \
       REF (form_wcharacter),	/* for 'C' */				      \
-      REF (form_floathex)	/* for 'A', 'a' */			      \
+      REF (form_floathex),	/* for 'A', 'a' */			      \
+      REF (form_unknown),       /* for 't' */				      \
+      REF (form_unknown)        /* for 'j' */				      \
     }
 
 
@@ -1178,6 +1191,16 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       is_long = sizeof (size_t) > sizeof (unsigned int);
       JUMP (*++f, step4_jumps);
 
+    LABEL (mod_ptrdiff_t):
+      is_longlong = sizeof (ptrdiff_t) > sizeof (unsigned long int);
+      is_long = sizeof (ptrdiff_t) > sizeof (unsigned int);
+      JUMP (*++f, step4_jumps);
+
+    LABEL (mod_intmax_t):
+      is_longlong = sizeof (intmax_t) > sizeof (unsigned long int);
+      is_long = sizeof (intmax_t) > sizeof (unsigned int);
+      JUMP (*++f, step4_jumps);
+
       /* Process current format.  */
       while (1)
 	{
diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c
index bd167b9a5b..ce5e5125f7 100644
--- a/stdio-common/vfscanf.c
+++ b/stdio-common/vfscanf.c
@@ -21,6 +21,7 @@
 #include <ctype.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <wctype.h>
@@ -407,7 +408,8 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
 	width = -1;
 
       /* Check for type modifiers.  */
-      while (*f == 'h' || *f == 'l' || *f == 'L' || *f == 'a' || *f == 'q')
+      while (*f == 'h' || *f == 'l' || *f == 'L' || *f == 'a' || *f == 'q'
+	     || *f == 'z' || *f == 't' || *f == 'j')
 	switch (*f++)
 	  {
 	  case 'h':
@@ -459,6 +461,30 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
 	       arg and fill it in with a malloc'd pointer.  */
 	    flags |= MALLOC;
 	    break;
+	  case 'z':
+	    if (flags & (SHORT|LONGDBL|CHAR))
+	      conv_error ();
+	    if (sizeof (size_t) > sizeof (unsigned long int))
+	      flags |= LONGDBL;
+	    else if (sizeof (size_t) > sizeof (unsigned int))
+	      flags |= LONG;
+	    break;
+	  case 'j':
+	    if (flags & (SHORT|LONGDBL|CHAR))
+	      conv_error ();
+	    if (sizeof (intmax_t) > sizeof (unsigned long int))
+	      flags |= LONGDBL;
+	    else if (sizeof (intmax_t) > sizeof (unsigned int))
+	      flags |= LONG;
+	    break;
+	  case 't':
+	    if (flags & (SHORT|LONGDBL|CHAR))
+	      conv_error ();
+	    if (sizeof (ptrdiff_t) > sizeof (unsigned long int))
+	      flags |= LONGDBL;
+	    else if (sizeof (ptrdiff_t) > sizeof (unsigned int))
+	      flags |= LONG;
+	    break;
 	  }
 
       /* End of the format string?  */