]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - stdio-common/scanf15.c
Prepare vfscanf to use __strtof128_internal
[thirdparty/glibc.git] / stdio-common / scanf15.c
index cc8aa2e6a6a954a9098f84d76eacf57f195c0ca2..a3ab15dea224d66e02eeb0306f6843d0b2117ae4 100644 (file)
@@ -1,5 +1,7 @@
 #undef _GNU_SOURCE
 #define _XOPEN_SOURCE 600
+#undef _LIBC
+#undef _IO_MTSAFE_IO
 /* The following macro definitions are a hack.  They word around disabling
    the GNU extension while still using a few internal headers.  */
 #define u_char unsigned char
@@ -50,5 +52,48 @@ main (void)
   else if (d != 5.25 || memcmp (c, " x", 2) != 0)
     FAIL ();
 
+  const char *tmpdir = getenv ("TMPDIR");
+  if (tmpdir == NULL || tmpdir[0] == '\0')
+    tmpdir = "/tmp";
+
+  char fname[strlen (tmpdir) + sizeof "/tst-scanf15.XXXXXX"];
+  sprintf (fname, "%s/tst-scanf15.XXXXXX", tmpdir);
+  if (fname == NULL)
+    FAIL ();
+
+  /* Create a temporary file.   */
+  int fd = mkstemp (fname);
+  if (fd == -1)
+    FAIL ();
+
+  FILE *fp = fdopen (fd, "w+");
+  if (fp == NULL)
+    FAIL ();
+  else
+    {
+      if (fputs (" 1.25s x", fp) == EOF)
+       FAIL ();
+      if (fseek (fp, 0, SEEK_SET) != 0)
+       FAIL ();
+      if (fscanf (fp, "%as%2c", &f, c) != 2)
+       FAIL ();
+      else if (f != 1.25 || memcmp (c, " x", 2) != 0)
+       FAIL ();
+
+      if (freopen (fname, "r", stdin) == NULL)
+       FAIL ();
+      else
+       {
+         if (scanf ("%as%2c", &f, c) != 2)
+           FAIL ();
+         else if (f != 1.25 || memcmp (c, " x", 2) != 0)
+           FAIL ();
+       }
+
+      fclose (fp);
+    }
+
+  remove (fname);
+
   return result;
 }