]> git.saurik.com Git - apple/libc.git/blob - gdtoa/FreeBSD/gdtoa-strtod.c.patch
e4b67d730d4977b3bc8295aadce3e6d42525a171
[apple/libc.git] / gdtoa / FreeBSD / gdtoa-strtod.c.patch
1 --- gdtoa-strtod.c.orig 2007-10-04 15:00:21.000000000 -0700
2 +++ gdtoa-strtod.c 2007-10-04 15:02:41.000000000 -0700
3 @@ -29,6 +29,8 @@
4 /* Please send bug reports to David M. Gay (dmg at acm dot org,
5 * with " at " changed at "@" and " dot " changed to "."). */
6
7 +#include "xlocale_private.h"
8 +
9 #include "gdtoaimp.h"
10 #ifndef NO_FENV_H
11 #include <fenv.h>
12 @@ -59,11 +61,11 @@
13 #endif
14
15 double
16 -strtod
17 +strtod_l
18 #ifdef KR_headers
19 - (s00, se) CONST char *s00; char **se;
20 + (s00, se, loc) CONST char *s00; char **se; locale_t loc;
21 #else
22 - (CONST char *s00, char **se)
23 + (CONST char *s00, char **se, locale_t loc)
24 #endif
25 {
26 #ifdef Avoid_Underflow
27 @@ -80,8 +82,12 @@
28 int inexact, oldinexact;
29 #endif
30 #ifdef Honor_FLT_ROUNDS
31 - int rounding;
32 + int rounding = Flt_Rounds;
33 #endif
34 +#ifdef USE_LOCALE
35 + char *decimal_point;
36 + int decimal_point_len;
37 +#endif /* USE_LOCALE */
38
39 sign = nz0 = nz = decpt = 0;
40 dval(rv) = 0.;
41 @@ -126,7 +132,7 @@
42 #else
43 #define fpi1 fpi
44 #endif
45 - switch((i = gethex(&s, &fpi1, &exp, &bb, sign)) & STRTOG_Retmask) {
46 + switch((i = gethex(&s, &fpi1, &exp, &bb, sign, loc)) & STRTOG_Retmask) {
47 case STRTOG_NoNumber:
48 s = s00;
49 sign = 0;
50 @@ -156,14 +162,22 @@
51 else if (nd < 16)
52 z = 10*z + c - '0';
53 nd0 = nd;
54 + NORMALIZE_LOCALE(loc);
55 #ifdef USE_LOCALE
56 - if (c == *localeconv()->decimal_point)
57 + decimal_point = localeconv_l(loc)->decimal_point;
58 + decimal_point_len = strlen(decimal_point);
59 + if (strncmp(s, decimal_point, decimal_point_len) == 0)
60 #else
61 if (c == '.')
62 #endif
63 {
64 decpt = 1;
65 +#ifdef USE_LOCALE
66 + s += decimal_point_len;
67 + c = *s;
68 +#else
69 c = *++s;
70 +#endif
71 if (!nd) {
72 for(; c == '0'; c = *++s)
73 nz++;
74 @@ -379,7 +393,7 @@
75 scale = 0;
76 #endif
77 #ifdef Honor_FLT_ROUNDS
78 - if ((rounding = Flt_Rounds) >= 2) {
79 + if (rounding >= 2) {
80 if (sign)
81 rounding = rounding == 2 ? 0 : 2;
82 else
83 @@ -512,7 +526,11 @@
84
85 /* Put digits into bd: true value = bd * 10^e */
86
87 - bd0 = s2b(s0, nd0, nd, y);
88 +#ifdef USE_LOCALE
89 + bd0 = s2b(s0, nd0, nd, y, decimal_point_len);
90 +#else
91 + bd0 = s2b(s0, nd0, nd, y, 1);
92 +#endif
93
94 for(;;) {
95 bd = Balloc(bd0->k);
96 @@ -956,7 +974,11 @@
97 dval(rv) *= dval(rv0);
98 #ifndef NO_ERRNO
99 /* try to avoid the bug of testing an 8087 register value */
100 +#if __DARWIN_UNIX03
101 + if (word0(rv) == 0 && word1(rv) == 0 || dval(rv) < DBL_MIN)
102 +#else /* !__DARWIN_UNIX03 */
103 if (word0(rv) == 0 && word1(rv) == 0)
104 +#endif /* __DARWIN_UNIX03 */
105 errno = ERANGE;
106 #endif
107 }
108 @@ -980,3 +1002,13 @@
109 return sign ? -dval(rv) : dval(rv);
110 }
111
112 + double
113 +strtod
114 +#ifdef KR_headers
115 + (s00, se) CONST char *s00; char **se;
116 +#else
117 + (CONST char *s00, char **se)
118 +#endif
119 +{
120 + return strtod_l(s00, se, __current_locale());
121 +}