* [PATCH] Add scanf/vfscanf/vscanf tests of long double without <stdio.h>
@ 2024-05-24 17:46 H.J. Lu
0 siblings, 0 replies; only message in thread
From: H.J. Lu @ 2024-05-24 17:46 UTC (permalink / raw)
To: libc-alpha
Update test-fscanf.c to add scanf/vfscanf/vscanf tests of long double
without including <stdio.h>.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
stdio-common/test-fscanf.c | 41 +++++++++++++++++++++++++++++++++-
stdio-common/test-fscanf.input | 3 +++
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/stdio-common/test-fscanf.c b/stdio-common/test-fscanf.c
index f2c4250b51..446d4a307d 100644
--- a/stdio-common/test-fscanf.c
+++ b/stdio-common/test-fscanf.c
@@ -1,4 +1,4 @@
-/* Test fscanf of long double without <stdio.h>.
+/* Test fscanf/scanf/vfscanf/vscanf of long double without <stdio.h>.
Copyright (C) 2024 Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -16,11 +16,35 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
+#include <stdarg.h>
#include <string.h>
struct FILE;
extern struct FILE *stdin;
extern int fscanf (struct FILE *, const char *, ...);
+extern int scanf (const char *, ...);
+extern int vfscanf (struct FILE *, const char *, va_list);
+extern int vscanf (const char *, va_list);
+
+static int
+wrap_vfscanf (struct FILE *fp, const char *format, ...)
+{
+ va_list ap;
+ va_start (ap, format);
+ int ret = vfscanf (fp, format, ap);
+ va_end (ap);
+ return ret;
+}
+
+static int
+wrap_vscanf (const char *format, ...)
+{
+ va_list ap;
+ va_start (ap, format);
+ int ret = vscanf (format, ap);
+ va_end (ap);
+ return ret;
+}
int
main (void)
@@ -30,6 +54,21 @@ main (void)
char name[50];
n = fscanf (stdin, "%d%Lf%s", &i, &x, name);
+ if (n != 3 || i != 25 || x != 24.5 || strcmp (name, "thompson"))
+ return 1;
+
+ n = scanf ("%d%Lf%s", &i, &x, name);
+
+ if (n != 3 || i != 25 || x != 24.5 || strcmp (name, "thompson"))
+ return 1;
+
+ n = wrap_vfscanf (stdin, "%d%Lf%s", &i, &x, name);
+
+ if (n != 3 || i != 25 || x != 24.5 || strcmp (name, "thompson"))
+ return 1;
+
+ n = wrap_vscanf ("%d%Lf%s", &i, &x, name);
+
if (n != 3 || i != 25 || x != 24.5 || strcmp (name, "thompson"))
return 1;
diff --git a/stdio-common/test-fscanf.input b/stdio-common/test-fscanf.input
index 69322cc51a..20859d314a 100644
--- a/stdio-common/test-fscanf.input
+++ b/stdio-common/test-fscanf.input
@@ -1 +1,4 @@
25 24.5 thompson
+25 24.5 thompson
+25 24.5 thompson
+25 24.5 thompson
--
2.45.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-05-24 17:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-24 17:46 [PATCH] Add scanf/vfscanf/vscanf tests of long double without <stdio.h> H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).