1 /* Read decimal floating point numbers.
2 This file is part of the GNU C Library.
3 Copyright (C) 1995-2022 Free Software Foundation, Inc.
4
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.
9
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.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #include <bits/floatn.h>
20
21 #ifdef FLOAT
22 # define BUILD_DOUBLE 0
23 #else
24 # define BUILD_DOUBLE 1
25 #endif
26
27 #if BUILD_DOUBLE
28 # if __HAVE_FLOAT64 && !__HAVE_DISTINCT_FLOAT64
29 # define strtof64 __hide_strtof64
30 # define wcstof64 __hide_wcstof64
31 # endif
32 # if __HAVE_FLOAT32X && !__HAVE_DISTINCT_FLOAT32X
33 # define strtof32x __hide_strtof32x
34 # define wcstof32x __hide_wcstof32x
35 # endif
36 #endif
37
38 #include <stdlib.h>
39 #include <wchar.h>
40 #include <locale/localeinfo.h>
41
42
43 #ifndef FLOAT
44 # include <math_ldbl_opt.h>
45 # define FLOAT double
46 # ifdef USE_WIDE_CHAR
47 # define STRTOF wcstod
48 # define STRTOF_L __wcstod_l
49 # else
50 # define STRTOF strtod
51 # define STRTOF_L __strtod_l
52 # endif
53 #endif
54
55 #ifdef USE_WIDE_CHAR
56 # include <wctype.h>
57 # define STRING_TYPE wchar_t
58 #else
59 # define STRING_TYPE char
60 #endif
61
62 #define INTERNAL(x) INTERNAL1(x)
63 #define INTERNAL1(x) __##x##_internal
64
65
66 FLOAT
INTERNAL(STRTOF)67 INTERNAL (STRTOF) (const STRING_TYPE *nptr, STRING_TYPE **endptr, int group)
68 {
69 return INTERNAL(STRTOF_L) (nptr, endptr, group, _NL_CURRENT_LOCALE);
70 }
71 #if defined _LIBC
libc_hidden_def(INTERNAL (STRTOF))72 libc_hidden_def (INTERNAL (STRTOF))
73 #endif
74
75
76 FLOAT
77 #ifdef weak_function
78 weak_function
79 #endif
80 STRTOF (const STRING_TYPE *nptr, STRING_TYPE **endptr)
81 {
82 return INTERNAL(STRTOF_L) (nptr, endptr, 0, _NL_CURRENT_LOCALE);
83 }
84 #if defined _LIBC
85 libc_hidden_def (STRTOF)
86 #endif
87
88 #ifdef LONG_DOUBLE_COMPAT
89 # if LONG_DOUBLE_COMPAT(libc, GLIBC_2_0)
90 # ifdef USE_WIDE_CHAR
91 compat_symbol (libc, wcstod, wcstold, GLIBC_2_0);
92 compat_symbol (libc, __wcstod_internal, __wcstold_internal, GLIBC_2_0);
93 # else
94 compat_symbol (libc, strtod, strtold, GLIBC_2_0);
95 compat_symbol (libc, __strtod_internal, __strtold_internal, GLIBC_2_0);
96 # endif
97 # endif
98 #endif
99
100 #if BUILD_DOUBLE
101 # if __HAVE_FLOAT64 && !__HAVE_DISTINCT_FLOAT64
102 # undef strtof64
103 # undef wcstof64
104 # ifdef USE_WIDE_CHAR
105 weak_alias (wcstod, wcstof64)
106 # else
107 weak_alias (strtod, strtof64)
108 # endif
109 # endif
110 # if __HAVE_FLOAT32X && !__HAVE_DISTINCT_FLOAT32X
111 # undef strtof32x
112 # undef wcstof32x
113 # ifdef USE_WIDE_CHAR
114 weak_alias (wcstod, wcstof32x)
115 # else
116 weak_alias (strtod, strtof32x)
117 # endif
118 # endif
119 #endif
120