From ad8a5511966f4e00625723fc83c0240ca8b08610 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sat, 24 May 2008 18:14:36 +0000 Subject: * 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 * 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. --- stdio-common/scanf15.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'stdio-common/scanf15.c') diff --git a/stdio-common/scanf15.c b/stdio-common/scanf15.c index cc8aa2e6a6..c56715c486 100644 --- a/stdio-common/scanf15.c +++ b/stdio-common/scanf15.c @@ -50,5 +50,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; } -- cgit v1.2.3