Message ID | 20240524150034.2125782-1-hjl.tools@gmail.com |
---|---|
State | New |
Headers | show |
Series | Test fscanf of long double without <stdio.h> | expand |
On Fri, May 24, 2024 at 8:00 AM H.J. Lu <hjl.tools@gmail.com> wrote: > Add a test for fscanf of long double without including <stdio.h>. > > Signed-off-by: H.J. Lu <hjl.tools@gmail.com> > --- > stdio-common/Makefile | 1 + > stdio-common/test-fscanf.c | 37 ++++++++++++++++++++++++++++++++++ > stdio-common/test-fscanf.input | 1 + > 3 files changed, 39 insertions(+) > create mode 100644 stdio-common/test-fscanf.c > create mode 100644 stdio-common/test-fscanf.input > > diff --git a/stdio-common/Makefile b/stdio-common/Makefile > index 6bc972af1a..274bece0a2 100644 > --- a/stdio-common/Makefile > +++ b/stdio-common/Makefile > @@ -193,6 +193,7 @@ tests := \ > scanf18 \ > scanf19 \ > temptest \ > + test-fscanf \ > test-fseek \ > test-fwrite \ > test-popen \ > diff --git a/stdio-common/test-fscanf.c b/stdio-common/test-fscanf.c > new file mode 100644 > index 0000000000..f2c4250b51 > --- /dev/null > +++ b/stdio-common/test-fscanf.c > @@ -0,0 +1,37 @@ > +/* Test fscanf of long double without <stdio.h>. > + Copyright (C) 2024 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + <https://www.gnu.org/licenses/>. */ > + > +#include <string.h> > + > +struct FILE; > +extern struct FILE *stdin; > +extern int fscanf (struct FILE *, const char *, ...); > + > +int > +main (void) > +{ > + int n, i; > + long double x; > + 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; > + > + return 0; > +} > diff --git a/stdio-common/test-fscanf.input > b/stdio-common/test-fscanf.input > new file mode 100644 > index 0000000000..69322cc51a > --- /dev/null > +++ b/stdio-common/test-fscanf.input > @@ -0,0 +1 @@ > +25 24.5 thompson > -- > 2.45.1 > > LGTM Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com> --Sunil
On Fri, May 24, 2024 at 8:44 AM Sunil Pandey <skpgkp2@gmail.com> wrote: > > > > On Fri, May 24, 2024 at 8:00 AM H.J. Lu <hjl.tools@gmail.com> wrote: >> >> Add a test for fscanf of long double without including <stdio.h>. >> >> Signed-off-by: H.J. Lu <hjl.tools@gmail.com> >> --- >> stdio-common/Makefile | 1 + >> stdio-common/test-fscanf.c | 37 ++++++++++++++++++++++++++++++++++ >> stdio-common/test-fscanf.input | 1 + >> 3 files changed, 39 insertions(+) >> create mode 100644 stdio-common/test-fscanf.c >> create mode 100644 stdio-common/test-fscanf.input >> >> diff --git a/stdio-common/Makefile b/stdio-common/Makefile >> index 6bc972af1a..274bece0a2 100644 >> --- a/stdio-common/Makefile >> +++ b/stdio-common/Makefile >> @@ -193,6 +193,7 @@ tests := \ >> scanf18 \ >> scanf19 \ >> temptest \ >> + test-fscanf \ >> test-fseek \ >> test-fwrite \ >> test-popen \ >> diff --git a/stdio-common/test-fscanf.c b/stdio-common/test-fscanf.c >> new file mode 100644 >> index 0000000000..f2c4250b51 >> --- /dev/null >> +++ b/stdio-common/test-fscanf.c >> @@ -0,0 +1,37 @@ >> +/* Test fscanf of long double without <stdio.h>. >> + Copyright (C) 2024 Free Software Foundation, Inc. >> + This file is part of the GNU C Library. >> + >> + The GNU C Library is free software; you can redistribute it and/or >> + modify it under the terms of the GNU Lesser General Public >> + License as published by the Free Software Foundation; either >> + version 2.1 of the License, or (at your option) any later version. >> + >> + The GNU C Library is distributed in the hope that it will be useful, >> + but WITHOUT ANY WARRANTY; without even the implied warranty of >> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU >> + Lesser General Public License for more details. >> + >> + You should have received a copy of the GNU Lesser General Public >> + License along with the GNU C Library; if not, see >> + <https://www.gnu.org/licenses/>. */ >> + >> +#include <string.h> >> + >> +struct FILE; >> +extern struct FILE *stdin; >> +extern int fscanf (struct FILE *, const char *, ...); >> + >> +int >> +main (void) >> +{ >> + int n, i; >> + long double x; >> + 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; >> + >> + return 0; >> +} >> diff --git a/stdio-common/test-fscanf.input b/stdio-common/test-fscanf.input >> new file mode 100644 >> index 0000000000..69322cc51a >> --- /dev/null >> +++ b/stdio-common/test-fscanf.input >> @@ -0,0 +1 @@ >> +25 24.5 thompson >> -- >> 2.45.1 >> > > LGTM > Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com> > > --Sunil On ppc64le, without <stdio.h>, vfscanf is used and with <stdio.h> __isoc23_vfscanfieee128 is used. I am reverting this since it doesn't work on all targets.
diff --git a/stdio-common/Makefile b/stdio-common/Makefile index 6bc972af1a..274bece0a2 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -193,6 +193,7 @@ tests := \ scanf18 \ scanf19 \ temptest \ + test-fscanf \ test-fseek \ test-fwrite \ test-popen \ diff --git a/stdio-common/test-fscanf.c b/stdio-common/test-fscanf.c new file mode 100644 index 0000000000..f2c4250b51 --- /dev/null +++ b/stdio-common/test-fscanf.c @@ -0,0 +1,37 @@ +/* Test fscanf of long double without <stdio.h>. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <string.h> + +struct FILE; +extern struct FILE *stdin; +extern int fscanf (struct FILE *, const char *, ...); + +int +main (void) +{ + int n, i; + long double x; + 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; + + return 0; +} diff --git a/stdio-common/test-fscanf.input b/stdio-common/test-fscanf.input new file mode 100644 index 0000000000..69322cc51a --- /dev/null +++ b/stdio-common/test-fscanf.input @@ -0,0 +1 @@ +25 24.5 thompson
Add a test for fscanf of long double without including <stdio.h>. Signed-off-by: H.J. Lu <hjl.tools@gmail.com> --- stdio-common/Makefile | 1 + stdio-common/test-fscanf.c | 37 ++++++++++++++++++++++++++++++++++ stdio-common/test-fscanf.input | 1 + 3 files changed, 39 insertions(+) create mode 100644 stdio-common/test-fscanf.c create mode 100644 stdio-common/test-fscanf.input