posix: Add invalid flags test for p{write,read}v2
[glibc.git] / stdlib / bug-strtod.c
blobb91f739104be70da31ada58ac959e5a01abd8a7f
1 /* Test to strtod etc for numbers like x000...0000.000e-nn.
2 This file is part of the GNU C Library.
3 Copyright (C) 2001-2017 Free Software Foundation, Inc.
4 Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
24 #include "tst-strtod.h"
26 #define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
27 static int \
28 test_strto ## FSUF (void) \
29 { \
30 char buf[300]; \
31 int cnt; \
32 int result = 0; \
34 for (cnt = 0; cnt < 200; ++cnt) \
35 { \
36 ssize_t n; \
37 FTYPE f; \
39 n = sprintf (buf, "%d", cnt); \
40 memset (buf + n, '0', cnt); \
41 sprintf (buf + n + cnt, ".000e-%d", cnt); \
42 f = strto ## FSUF (buf, NULL); \
44 if (f != (FTYPE) cnt) \
45 { \
46 char fstr[FSTRLENMAX]; \
47 char fcntstr[FSTRLENMAX]; \
48 FTOSTR (fstr, sizeof (fstr), "%g", f); \
49 FTOSTR (fcntstr, sizeof (fstr), "%g", (FTYPE) cnt); \
50 printf ("strto" #FSUF "(\"%s\") " \
51 "failed for cnt == %d (%s instead of %s)\n", \
52 buf, cnt, fstr, fcntstr); \
53 result = 1; \
54 } \
55 else \
56 printf ( "strto" #FSUF "() fine for cnt == %d\n", cnt); \
57 } \
58 return result; \
61 GEN_TEST_STRTOD_FOREACH (TEST_STRTOD)
63 int
64 main (void)
66 return STRTOD_TEST_FOREACH (test_strto);