about summary refs log tree commit diff
path: root/stdio
diff options
context:
space:
mode:
Diffstat (limited to 'stdio')
-rw-r--r--stdio/internals.c2
-rw-r--r--stdio/printf_fp.c9
-rw-r--r--stdio/vfscanf.c81
3 files changed, 56 insertions, 36 deletions
diff --git a/stdio/internals.c b/stdio/internals.c
index b01c5bd531..c238bf39f9 100644
--- a/stdio/internals.c
+++ b/stdio/internals.c
@@ -265,7 +265,7 @@ DEFUN(flushbuf, (fp, c),
 	    }
 	}
 
-      if (fp->__bufp - fp->__buffer <= buffer_offset)
+      if (fp->__bufp - fp->__buffer <= buffer_offset && flush_only)
 	{
 	  /* There is nothing new in the buffer, only data that
 	     was read back aligned from the file.  */
diff --git a/stdio/printf_fp.c b/stdio/printf_fp.c
index 42443fa003..33fe427999 100644
--- a/stdio/printf_fp.c
+++ b/stdio/printf_fp.c
@@ -36,12 +36,11 @@ Cambridge, MA 02139, USA.  */
 #include <limits.h>
 #include <math.h>
 #include <printf.h>
-#include <stdarg.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
 
-/* #define NDEBUG 1 */
+#define NDEBUG			/* Undefine this for debugging assertions.  */
 #include <assert.h>
 
 /* This defines make it possible to use the same code for GNU C library and
@@ -133,7 +132,7 @@ int
 __printf_fp (fp, info, args)
      FILE *fp;
      const struct printf_info *info;
-     va_list *args;
+     const **const args;
 {
   /* The floating-point value to output.  */
   union
@@ -254,7 +253,7 @@ __printf_fp (fp, info, args)
   /* Fetch the argument value.	*/
   if (info->is_long_double && sizeof (long double) > sizeof (double))
     {
-      fpnum.ldbl = va_arg (*args, LONG_DOUBLE);
+      fpnum.ldbl = *(const long double *) args[0];
 
       /* Check for special values: not a number or infinity.  */
       if (__isnanl (fpnum.ldbl))
@@ -279,7 +278,7 @@ __printf_fp (fp, info, args)
     }
   else
     {
-      fpnum.dbl = va_arg (*args, double);
+      fpnum.dbl = *(const double *) args[0];
 
       /* Check for special values: not a number or infinity.  */
       if (__isnan (fpnum.dbl))
diff --git a/stdio/vfscanf.c b/stdio/vfscanf.c
index 47781ed566..9a9e3bb79c 100644
--- a/stdio/vfscanf.c
+++ b/stdio/vfscanf.c
@@ -57,6 +57,7 @@ DEFUN(__vfscanf, (s, format, arg),
   register int c;		/* Last char read.  */
   register int do_assign;	/* Whether to do an assignment.  */
   register int width;		/* Maximum field width.  */
+  int group_flag;		/* %' modifier flag.  */
 
   /* Type modifiers.  */
   char is_short, is_long, is_long_double;
@@ -76,8 +77,13 @@ DEFUN(__vfscanf, (s, format, arg),
   /* Signedness for integral numbers.  */
   int number_signed;
   /* Integral holding variables.  */
-  long int num;
-  unsigned long int unum;
+  union
+    {
+      long long int q;
+      unsigned long long int uq;
+      long int l;
+      unsigned long int ul;
+    } num;
   /* Character-buffer pointer.  */
   register char *str, **strptr;
   size_t strsize;
@@ -93,8 +99,8 @@ DEFUN(__vfscanf, (s, format, arg),
     }
 
   /* Figure out the decimal point character.  */
-  if (mbtowc(&decimal, _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT),
-	     strlen (_NL_CURRENT (LC_NUMERIC, DECIMAL_POINT))) <= 0)
+  if (mbtowc (&decimal, _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT),
+	      strlen (_NL_CURRENT (LC_NUMERIC, DECIMAL_POINT))) <= 0)
     decimal = (wchar_t) *_NL_CURRENT (LC_NUMERIC, DECIMAL_POINT);
 
   c = inchar();
@@ -102,10 +108,10 @@ DEFUN(__vfscanf, (s, format, arg),
   /* Run through the format string.  */
   while (*f != '\0')
     {
-      if (!isascii(*f))
+      if (!isascii (*f))
 	{
 	  /* Non-ASCII, may be a multibyte.  */
-	  int len = mblen(f, strlen(f));
+	  int len = mblen (f, strlen(f));
 	  if (len > 0)
 	    {
 	      while (len-- > 0)
@@ -139,15 +145,20 @@ DEFUN(__vfscanf, (s, format, arg),
 	  continue;
 	}
 
-      /* Check for the assignment-suppressant.  */
-      if (*f == '*')
-	{
-	  do_assign = 0;
-	  ++f;
-	}
-      else
-	do_assign = 1;
-		
+      /* Check for the assignment-suppressant and the number grouping flag.  */
+      do_assign = 1;
+      group_flag = 0;
+      while (*f == '*' || *f == '\'')
+	switch (*f++)
+	  {
+	  case '*':
+	    do_assign = 0;
+	    break;
+	  case '\'':
+	    group_flag = 1;
+	    break;
+	  }
+
       /* Find the maximum field width.  */
       width = 0;
       while (isdigit(*f))
@@ -396,9 +407,19 @@ DEFUN(__vfscanf, (s, format, arg),
 	  /* Convert the number.  */
 	  *w = '\0';
 	  if (number_signed)
-	    num = strtol (work, &w, base);
+	    {
+	      if (is_longlong)
+		num.q = __strtoq_internal (work, &w, base, group_flag);
+	      else
+		num.uq = __strtouq_internal (work, &w, base, group_flag);
+	    }
 	  else
-	    unum = strtoul (work, &w, base);
+	    {
+	      if (is_long_double)
+		num.l = __strtol_internal (work, &w, base, group_flag);
+	      else
+		num.ul = __strtoul_internal (work, &w, base, group_flag);
+	    }
 	  if (w == work)
 	    conv_error ();
 
@@ -407,25 +428,25 @@ DEFUN(__vfscanf, (s, format, arg),
 	      if (! number_signed)
 		{
 		  if (is_longlong)
-		    *va_arg (arg, unsigned LONGLONG int *) = unum;
+		    *va_arg (arg, unsigned LONGLONG int *) = num.uq;
 		  else if (is_long)
-		    *va_arg (arg, unsigned long int *) = unum;
+		    *va_arg (arg, unsigned long int *) = num.ul;
 		  else if (is_short)
 		    *va_arg (arg, unsigned short int *)
-		      = (unsigned short int) unum;
+		      = (unsigned short int) num.ul;
 		  else
-		    *va_arg(arg, unsigned int *) = (unsigned int) unum;
+		    *va_arg (arg, unsigned int *) = (unsigned int) num.ul;
 		}
 	      else
 		{
 		  if (is_longlong)
-		    *va_arg(arg, LONGLONG int *) = num;
+		    *va_arg (arg, LONGLONG int *) = num.q;
 		  else if (is_long)
-		    *va_arg(arg, long int *) = num;
+		    *va_arg (arg, long int *) = num.l;
 		  else if (is_short)
-		    *va_arg(arg, short int *) = (short int) num;
+		    *va_arg (arg, short int *) = (short int) num.l;
 		  else
-		    *va_arg(arg, int *) = (int) num;
+		    *va_arg (arg, int *) = (int) num.l;
 		}
 	      ++done;
 	    }
@@ -482,19 +503,19 @@ DEFUN(__vfscanf, (s, format, arg),
 	  *w = '\0';
 	  if (is_long_double)
 	    {
-	      long double d = __strtold (work, &w);
+	      long double d = __strtold_internal (work, &w, group_flag);
 	      if (do_assign && w != work)
 		*va_arg (arg, long double *) = d;
 	    }
 	  else if (is_long)
 	    {
-	      double d = strtod (work, &w);
+	      double d = __strtod_internal (work, &w, group_flag);
 	      if (do_assign && w != work)
 		*va_arg (arg, double *) = d;
 	    }
 	  else
 	    {
-	      float d = __strtof (work, &w);
+	      float d = __strtof_internal (work, &w, group_flag);
 	      if (do_assign && w != work)
 		*va_arg (arg, float *) = d;
 	    }
@@ -536,7 +557,7 @@ DEFUN(__vfscanf, (s, format, arg),
 	    conv_error();
 
 	  *w = '\0';
-	  unum = read_in;
+	  num.ul = read_in;
 	  do
 	    {
 	      if ((strchr (work, c) == NULL) != not_in)
@@ -545,7 +566,7 @@ DEFUN(__vfscanf, (s, format, arg),
 	      if (width > 0)
 		--width;
 	    } while (inchar () != EOF && width != 0);
-	  if (read_in == unum)
+	  if (read_in == num.ul)
 	    conv_error ();
 
 	  if (do_assign)