about summary refs log tree commit diff
path: root/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat-template.c
diff options
context:
space:
mode:
authorGabriel F. T. Gomes <gabrielftg@linux.ibm.com>2019-07-11 11:47:43 -0300
committerGabriel F. T. Gomes <gabrielftg@linux.ibm.com>2019-12-13 18:02:09 -0300
commitf1a0eb5b6762b315517469da47735c51bde6f4ad (patch)
treeffc1415094cd0fe5e4a08c061fd59b7417005314 /sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat-template.c
parent348787f06902b971d76dbab3f05d54c0b5c36131 (diff)
downloadglibc-f1a0eb5b6762b315517469da47735c51bde6f4ad.tar.gz
glibc-f1a0eb5b6762b315517469da47735c51bde6f4ad.tar.xz
glibc-f1a0eb5b6762b315517469da47735c51bde6f4ad.zip
ldbl-128ibm-compat: Add ISO C99 versions of scanf functions
In the format string for *scanf functions, the '%as', '%aS', and '%a[]'
modifiers behave differently depending on ISO C99 compatibility.  When
_GNU_SOURCE is defined and -std=c89 is passed to the compiler, these
functions behave like ascanf, and the modifiers allocate memory for the
output.  Otherwise, the ISO C99 compliant version of these functions is
used, and the modifiers consume a floating-point argument.  This patch
adds the IEEE binary128 variant of ISO C99 compliant functions for the
third long double format on powerpc64le.

Tested for powerpc64le.

Reviewed-by: Paul E. Murphy <murphyp@linux.ibm.com>
Diffstat (limited to 'sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat-template.c')
-rw-r--r--sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat-template.c73
1 files changed, 45 insertions, 28 deletions
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat-template.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat-template.c
index 3dbed79b68..9bdf6daa0b 100644
--- a/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat-template.c
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-scanf-ldbl-compat-template.c
@@ -24,92 +24,109 @@
 
 #include <support/check.h>
 
-#define CLEAR								\
+#define CLEAR_VARGS							\
   va_start (args, format);						\
-  ld = va_arg (args, long double *);					\
-  *ld = 0;								\
+  ldptr = va_arg (args, long double *);					\
+  fptr = va_arg (args, float *);					\
+  *ldptr = 0;								\
+  *fptr = 0;								\
   va_end (args);
 
-#define CLEAR_VALUE value = 0;
-
-#define CHECK								\
+#define CHECK_VARGS							\
   va_start (args, format);						\
-  ld = va_arg (args, long double *);					\
+  ldptr = va_arg (args, long double *);					\
+  fptr = va_arg (args, float *);					\
   va_end (args);							\
-  if (*ld == -1.0L)							\
+  if (*ldptr == -1 && *fptr == -2)					\
     printf ("OK");							\
   else									\
-    printf ("ERROR (%.60Lf)", *ld);					\
+    printf ("ERROR (%Lf %f)", *ldptr, *fptr);				\
   printf ("\n");
 
+#define CLEAR_VALUE							\
+  ld = 0;								\
+  f = 0;
+
 #define CHECK_VALUE							\
-  if (value == -1.0L)							\
+  if (ld == -1 && f == -2)						\
     printf ("OK");							\
   else									\
-    printf ("ERROR (%.60Lf)", value);					\
+    printf ("ERROR (%Lf %f)", ld, f);					\
   printf ("\n");
 
 static void
 do_test_call (FILE *stream, CHAR *string, const CHAR *format, ...)
 {
-  long double value;
-  long double *ld;
+  float f;
+  long double ld;
+  float *fptr;
+  long double *ldptr;
   va_list args;
 
   CLEAR_VALUE
   printf ("fscanf: ");
-  FSCANF (stream, format, &value);
+  FSCANF (stream, format, &ld, &f);
   CHECK_VALUE
 
   CLEAR_VALUE
   printf ("scanf: ");
-  SCANF (format, &value);
+  SCANF (format, &ld, &f);
   CHECK_VALUE
 
   CLEAR_VALUE
   printf ("sscanf: ");
-  SSCANF (string, format, &value);
+  SSCANF (string, format, &ld, &f);
   CHECK_VALUE
 
-  CLEAR
+  CLEAR_VARGS
   printf ("vfscanf: ");
   va_start (args, format);
   VFSCANF (stream, format, args);
   va_end (args);
-  CHECK
+  CHECK_VARGS
 
-  CLEAR
+  CLEAR_VARGS
   printf ("vscanf: ");
   va_start (args, format);
   VSCANF (format, args);
   va_end (args);
-  CHECK
+  CHECK_VARGS
 
-  CLEAR
+  CLEAR_VARGS
   printf ("vsscanf: ");
   va_start (args, format);
   VSSCANF (string, format, args);
   va_end (args);
-  CHECK
+  CHECK_VARGS
 }
 
 static int
 do_test (void)
 {
   CHAR string[256];
+  float f;
   long double ld;
 
   /* Scan in decimal notation.  */
   STRCPY (string,
-	  L ("-1.0\n")
-	  L ("-1.0\n") );
-  do_test_call (stdin, string, L("%Lf"), &ld);
+	  L ("-1.0 -2.0\n")
+	  L ("-1.0 -2.0\n") );
+  do_test_call (stdin, string, L("%Lf %f"), &ld, &f);
 
   /* Scan in hexadecimal notation.  */
   STRCPY (string,
-	  L ("-0x1.0p+0\n")
-	  L ("-0x1.0p+0\n") );
-  do_test_call (stdin, string, L("%La"), &ld);
+	  L ("-0x1.0p+0 -0x2.0p+0\n")
+	  L ("-0x1.0p+0 -0x2.0p+0\n") );
+  /* For ISO C99, scan the single-precision value with "%as" to test
+     that __isoc99_*scanf ignores the 's'.  For DEPRECATED_SCANF, do not
+     use "%as", because that would try to scan a string and allocate
+     space for it.  */
+#if __GLIBC_USE (DEPRECATED_SCANF)
+# define FMT "%La %a"
+#else
+# define FMT "%La %as"
+#endif
+  do_test_call (stdin, string, L(FMT), &ld, &f);
 
   return 0;
 }