(td_thr_tls_get_addr): Fix reference to dtv.
[glibc.git] / stdio-common / tst-sscanf.c
blob778b4ecf8a4c8dfdf259bb0ad7ce986876d9dcca
1 /* Copyright (C) 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2000.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <locale.h>
24 const char *str_double[] =
26 "-.10000E+020.20000E+020.25000E+010.40000E+010.50000E+010.12500E+01",
27 "0.10000E+020.20000E+020.25000E+010.40000E+010.50000E+010.12500E+01",
28 "-1234567E0198765432E0912345678901987654321091234567890198765432109",
29 "-0.1000E+020.20000E+020.25000E+010.40000E+010.50000E+010.12500E+01"
32 const double val_double[] =
34 -.10000E+02, 0.20000E+02, 0.25000E+01, 0.40000E+01, 0.50000E+01, 0.12500E+01,
35 0.10000E+02, 0.20000E+02, 0.25000E+01, 0.40000E+01, 0.50000E+01, 0.12500E+01,
36 -1234567E01, 98765432E09, 12345678901, 98765432109, 12345678901, 98765432109,
37 -0.1000E+02, 0.20000E+02, 0.25000E+01, 0.40000E+01, 0.50000E+01, 0.12500E+01
40 const char *str_long[] =
42 "-12345678987654321123456789987654321123456789987654321",
43 "-12345678987654321123456789987654321123456789987654321",
44 "-12,345,678987,654,321123,456,789987,654,321123,456,789987,654,321",
45 "-12,345,678987,654,321123,456,789987,654,321123,456,789987,654,321"
48 const char *fmt_long[] =
50 "%9ld%9ld%9ld%9ld%9ld%9ld",
51 "%I9ld%I9ld%I9ld%I9ld%I9ld%I9ld",
52 "%'11ld%'11ld%'11ld%'11ld%'11ld%'11ld",
53 "%I'11ld%I'11ld%I'11ld%I'11ld%I'11ld%I'11ld"
56 const long int val_long[] =
58 -12345678, 987654321, 123456789, 987654321, 123456789, 987654321
61 int
62 main (void)
64 double d[6];
65 long l[6];
66 int i, j;
67 int tst_locale;
68 int result = 0;
70 tst_locale = 1;
71 if (tst_locale)
72 if (setlocale (LC_ALL, "en_US.ISO-8859-1") == NULL)
74 puts ("Failed to set en_US locale, skipping locale related tests");
75 tst_locale = 0;
78 for (i = 0; i < 4; ++i)
80 if (sscanf (str_double[i], "%11lf%11lf%11lf%11lf%11lf%11lf",
81 &d[0], &d[1], &d[2], &d[3], &d[4], &d[5]) != 6)
83 printf ("Double sscanf test %d wrong number of "
84 "assigned inputs\n", i);
85 result = 1;
87 else
88 for (j = 0; j < 6; ++j)
89 if (d[j] != val_double[6 * i + j])
91 printf ("Double sscanf test %d failed (%g instead of %g)\n",
92 i, d[j], val_double[6 * i + j]);
93 result = 1;
94 break;
98 for (i = 0; i < 4; ++i)
100 if (sscanf (str_long[i], fmt_long[i],
101 &l[0], &l[1], &l[2], &l[3], &l[4], &l[5]) != 6)
103 printf ("Integer sscanf test %d wrong number of "
104 "assigned inputs\n", i);
105 result = 1;
107 else
108 for (j = 0; j < 6; ++j)
109 if (l[j] != val_long[j])
111 printf ("Integer sscanf test %d failed (%ld instead %ld)\n",
112 i, l[j], val_long[j]);
113 result = 1;
114 break;
117 if (! tst_locale)
118 break;
121 return result;