strtold_subr.c revision 1.2 1 1.2 joerg /* $NetBSD: strtold_subr.c,v 1.2 2013/04/18 21:54:11 joerg Exp $ */
2 1.1 kleink
3 1.1 kleink /*
4 1.1 kleink * Written by Klaus Klein <kleink (at) NetBSD.org>, November 16, 2005.
5 1.1 kleink * Public domain.
6 1.1 kleink */
7 1.1 kleink
8 1.1 kleink /*
9 1.1 kleink * NOTICE: This is not a standalone file. To use it, #include it in
10 1.1 kleink * the format-specific strtold_*.c, like so:
11 1.1 kleink *
12 1.1 kleink * #define GDTOA_LD_FMT <gdtoa extended-precision format code>
13 1.1 kleink * #include "strtold_subr.c"
14 1.1 kleink */
15 1.1 kleink
16 1.1 kleink #include <sys/cdefs.h>
17 1.1 kleink #if defined(LIBC_SCCS) && !defined(lint)
18 1.2 joerg __RCSID("$NetBSD: strtold_subr.c,v 1.2 2013/04/18 21:54:11 joerg Exp $");
19 1.1 kleink #endif /* LIBC_SCCS and not lint */
20 1.1 kleink
21 1.1 kleink #include "namespace.h"
22 1.1 kleink #include <math.h>
23 1.1 kleink #include <stdlib.h>
24 1.1 kleink #include "gdtoa.h"
25 1.1 kleink
26 1.2 joerg #include <locale.h>
27 1.2 joerg #include "setlocale_local.h"
28 1.2 joerg
29 1.1 kleink #ifdef __weak_alias
30 1.1 kleink __weak_alias(strtold, _strtold)
31 1.2 joerg __weak_alias(strtold_l, _strtold_l)
32 1.1 kleink #endif
33 1.1 kleink
34 1.1 kleink #ifndef __HAVE_LONG_DOUBLE
35 1.1 kleink #error no extended-precision long double type
36 1.1 kleink #endif
37 1.1 kleink
38 1.1 kleink #ifndef GDTOA_LD_FMT
39 1.1 kleink #error GDTOA_LD_FMT must be defined by format-specific source file
40 1.1 kleink #endif
41 1.1 kleink
42 1.1 kleink #define STRTOP(x) __CONCAT(strtop, x)
43 1.1 kleink
44 1.2 joerg static long double
45 1.2 joerg _int_strtold_l(const char *nptr, char **endptr, locale_t loc)
46 1.1 kleink {
47 1.1 kleink long double ld;
48 1.1 kleink
49 1.2 joerg (void)STRTOP(GDTOA_LD_FMT)(nptr, endptr, &ld, loc);
50 1.1 kleink return ld;
51 1.1 kleink }
52 1.2 joerg
53 1.2 joerg long double
54 1.2 joerg strtold(CONST char *s, char **sp)
55 1.2 joerg {
56 1.2 joerg return _int_strtold_l(s, sp, *_current_locale());
57 1.2 joerg }
58 1.2 joerg
59 1.2 joerg long double
60 1.2 joerg strtold_l(CONST char *s, char **sp, locale_t loc)
61 1.2 joerg {
62 1.2 joerg if (loc == NULL)
63 1.2 joerg loc = _C_locale;
64 1.2 joerg return _int_strtold_l(s, sp, loc);
65 1.2 joerg }
66