1 /* $NetBSD: src/lib/libc/locale/wcstod.c,v 1.4 2001/10/28 12:08:43 yamt Exp $ */
2 /* $DragonFly: src/lib/libc/locale/wcstod.c,v 1.1 2005/03/16 07:54:41 joerg Exp $ */
5 * Copyright (c)1999, 2000, 2001 Citrus Project,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * $Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstod.c,v 1.2 2001/09/27 16:23:57 yamt Exp $
32 #include <sys/cdefs.h>
40 #define _L(x) __CONCAT(L,x)
41 #define _LC(x) __CONCAT(L,x)
44 wcstod(const wchar_t *nptr
, wchar_t **endptr
)
53 * we do only check length of string
54 * and give it over strtod.
58 /* skip space first */
59 while (iswspace(*src
)) {
63 /* get length of string */
65 if (wcschr(_L("+-"), *src
))
67 size
= wcsspn(src
, _L("0123456789"));
69 if (*src
== _LC('.')) {/* XXX use localeconv */
71 size
= wcsspn(src
, _L("0123456789"));
74 if (wcschr(_L("Ee"), *src
)) {
76 if (wcschr(_L("+-"), *src
))
78 size
= wcsspn(src
, _L("0123456789"));
84 * convert to a char-string and pass it to strtod.
86 * since all chars used to represent a double-constant
87 * are in the portable character set, we can assume
88 * that they are 1-byte chars.
96 size_t size_converted
;
99 buf
= malloc(size
+ 1);
102 errno
= ENOMEM
; /* XXX */
107 memset(&st
, 0, sizeof(st
));
108 size_converted
= wcsrtombs(buf
, &s
, size
, &st
);
109 if (size
!= size_converted
) {
110 /* XXX should not happen */
117 result
= strtod(buf
, &end
);
122 /* LINTED bad interface */
123 *endptr
= (wchar_t*)start
+ (end
- buf
);
129 /* LINTED bad interface */
130 *endptr
= (wchar_t*)start
;