aboutsummaryrefslogtreecommitdiff
path: root/stdio-common/scanf14.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2008-05-24 18:14:36 +0000
committerJakub Jelinek <jakub@redhat.com>2008-05-24 18:14:36 +0000
commitad8a5511966f4e00625723fc83c0240ca8b08610 (patch)
tree6ed6157ae12a6af611d39bb8a819dc5edca438b9 /stdio-common/scanf14.c
parente20038838008fdc87dc36d256e72190a39f17a1a (diff)
downloadglibc-ad8a5511966f4e00625723fc83c0240ca8b08610.tar
glibc-ad8a5511966f4e00625723fc83c0240ca8b08610.tar.gz
glibc-ad8a5511966f4e00625723fc83c0240ca8b08610.tar.bz2
glibc-ad8a5511966f4e00625723fc83c0240ca8b08610.zip
* libio/stdio.h (vscanf): Fix -std=c99 redirect.
* stdio-common/Makefile (tests): Add scanf16 and scanf17. (CFLAGS-scanf17.c): New. * stdio-common/scanf14.c (main): Add fscanf and scanf tests. * stdio-common/scanf15.c (main): Likewise. * stdio-common/scanf16.c: New test. * stdio-common/scanf17.c: New test. 2008-05-24 Jakub Jelinek <jakub@redhat.com> * libio/stdio.h (vscanf): Fix -std=c99 redirect. * stdio-common/Makefile (tests): Add scanf16 and scanf17. (CFLAGS-scanf17.c): New. * stdio-common/scanf14.c (main): Add fscanf and scanf tests. * stdio-common/scanf15.c (main): Likewise. * stdio-common/scanf16.c: New test. * stdio-common/scanf17.c: New test.
Diffstat (limited to 'stdio-common/scanf14.c')
-rw-r--r--stdio-common/scanf14.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/stdio-common/scanf14.c b/stdio-common/scanf14.c
index 387ceba4bb..6ca5c7c567 100644
--- a/stdio-common/scanf14.c
+++ b/stdio-common/scanf14.c
@@ -59,5 +59,58 @@ 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-scanf14.XXXXXX"];
+ sprintf (fname, "%s/tst-scanf14.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", &sp, c) != 2)
+ FAIL ();
+ else
+ {
+ if (strcmp (sp, "1.25s") != 0 || memcmp (c, " x", 2) != 0)
+ FAIL ();
+ memset (sp, 'x', sizeof "1.25s");
+ free (sp);
+ }
+
+ if (freopen (fname, "r", stdin) == NULL)
+ FAIL ();
+ else
+ {
+ if (scanf ("%as%2c", &sp, c) != 2)
+ FAIL ();
+ else
+ {
+ if (strcmp (sp, "1.25s") != 0 || memcmp (c, " x", 2) != 0)
+ FAIL ();
+ memset (sp, 'x', sizeof "1.25s");
+ free (sp);
+ }
+ }
+
+ fclose (fp);
+ }
+
+ remove (fname);
+
return result;
}