]> git.saurik.com Git - apple/libc.git/blame - gdtoa/FreeBSD/gdtoa-strtodg.c.patch
Libc-763.11.tar.gz
[apple/libc.git] / gdtoa / FreeBSD / gdtoa-strtodg.c.patch
CommitLineData
1f2f436a
A
1--- gdtoa-strtodg.c.orig 2010-01-29 16:43:20.000000000 -0800
2+++ gdtoa-strtodg.c 2010-01-29 18:13:37.000000000 -0800
34e8f829 3@@ -29,13 +29,29 @@ THIS SOFTWARE.
3d9156a7
A
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
11 #ifdef USE_LOCALE
224c7076
A
12 #include "locale.h"
13 #endif
14
15- static CONST int
16+#define fivesbits __fivesbits_D2A
17+#define all_on __all_on_D2A
18+#define set_ones __set_ones_D2A
19+#define rvOK __rvOK_D2A
20+#define mantbits __mantbits_D2A
21+
22+#ifdef BUILDING_VARIANT
23+extern CONST int fivesbits[];
24+int all_on(Bigint *b, int n);
25+Bigint *set_ones(Bigint *b, int n);
1f2f436a
A
26+int rvOK(U *d, FPI *fpi, Long *exp, ULong *bits, int exact, int rd, int *irv);
27+int mantbits(U *d);
224c7076
A
28+#else /* !BUILDING_VARIANT */
29+
30+ __private_extern__ CONST int
31 fivesbits[] = { 0, 3, 5, 7, 10, 12, 14, 17, 19, 21,
32 24, 26, 28, 31, 33, 35, 38, 40, 42, 45,
33 47, 49, 52
34e8f829
A
34@@ -121,7 +137,7 @@ decrement(Bigint *b)
35 #endif
224c7076
A
36 }
37
38- static int
39+ __private_extern__ int
40 #ifdef KR_headers
41 all_on(b, n) Bigint *b; int n;
42 #else
34e8f829 43@@ -168,7 +184,7 @@ set_ones(Bigint *b, int n)
224c7076
A
44 return b;
45 }
46
47- static int
48+ __private_extern__ int
49 rvOK
50 #ifdef KR_headers
51 (d, fpi, exp, bits, exact, rd, irv)
34e8f829 52@@ -289,7 +305,7 @@ rvOK
224c7076
A
53 return rv;
54 }
55
56- static int
57+ __private_extern__ int
58 #ifdef KR_headers
1f2f436a 59 mantbits(d) U *d;
224c7076 60 #else
1f2f436a 61@@ -312,13 +328,15 @@ mantbits(U *d)
224c7076
A
62 return P - 32 - lo0bits(&L);
63 }
64
65+#endif /* BUILDING_VARIANT */
66+
3d9156a7
A
67 int
68 strtodg
69 #ifdef KR_headers
70- (s00, se, fpi, exp, bits)
71- CONST char *s00; char **se; FPI *fpi; Long *exp; ULong *bits;
72+ (s00, se, fpi, exp, bits, loc)
73+ CONST char *s00; char **se; FPI *fpi; Long *exp; ULong *bits; locale_t loc;
74 #else
75- (CONST char *s00, char **se, FPI *fpi, Long *exp, ULong *bits)
76+ (CONST char *s00, char **se, FPI *fpi, Long *exp, ULong *bits, locale_t loc)
77 #endif
78 {
79 int abe, abits, asub;
1f2f436a
A
80@@ -327,21 +345,23 @@ strtodg
81 int j, k, nbits, nd, nd0, nf, nz, nz0, rd, rvbits, rve, rve1, sign;
82 int sudden_underflow;
83 CONST char *s, *s0, *s1;
84+ char *strunc = NULL;
85 double adj0, tol;
86 Long L;
87 U adj, rv;
34e8f829 88 ULong *b, *be, y, z;
224c7076 89 Bigint *ab, *bb, *bb1, *bd, *bd0, *bs, *delta, *rvb, *rvb0;
1f2f436a
A
90 #ifdef USE_LOCALE /*{{*/
91+ NORMALIZE_LOCALE(loc);
34e8f829
A
92 #ifdef NO_LOCALE_CACHE
93- char *decimalpoint = localeconv()->decimal_point;
94+ char *decimalpoint = localeconv_l(loc)->decimal_point;
1f2f436a 95 int dplen = strlen(decimalpoint);
34e8f829
A
96 #else
97 char *decimalpoint;
98 static char *decimalpoint_cache;
1f2f436a 99 static int dplen;
34e8f829
A
100 if (!(s0 = decimalpoint_cache)) {
101- s0 = localeconv()->decimal_point;
102+ s0 = localeconv_l(loc)->decimal_point;
1f2f436a 103 if ((decimalpoint_cache = (char*)MALLOC(strlen(s0) + 1))) {
34e8f829
A
104 strcpy(decimalpoint_cache, s0);
105 s0 = decimalpoint_cache;
1f2f436a 106@@ -388,7 +408,7 @@ strtodg
3d9156a7
A
107 switch(s[1]) {
108 case 'x':
109 case 'X':
110- irv = gethex(&s, fpi, exp, &rvb, sign);
111+ irv = gethex(&s, fpi, exp, &rvb, sign, loc);
112 if (irv == STRTOG_NoNumber) {
113 s = s00;
114 sign = 0;
1f2f436a
A
115@@ -525,6 +545,7 @@ strtodg
116 }
117 goto ret;
118 }
119+ TRUNCATE_DIGITS(s0, strunc, nd, nd0, nf, fpi->nbits, fpi->emin, dplen);
120
121 irv = STRTOG_Normal;
122 e1 = e -= nf;
123@@ -693,6 +714,10 @@ strtodg
3d9156a7
A
124 rvb->x[0] = 0;
125 *exp = emin;
126 irv = STRTOG_Underflow | STRTOG_Inexlo;
34e8f829
A
127+/* When __DARWIN_UNIX03 is set, we don't need this (errno is set later) */
128+#if !defined(NO_ERRNO) && !__DARWIN_UNIX03
3d9156a7
A
129+ errno = ERANGE;
130+#endif
131 goto ret;
132 }
133 rvb->x[0] = rvb->wds = rvbits = 1;
1f2f436a 134@@ -1038,7 +1063,7 @@ strtodg
34e8f829
A
135 if (sudden_underflow) {
136 rvb->wds = 0;
137 irv = STRTOG_Underflow | STRTOG_Inexlo;
138-#ifndef NO_ERRNO
224c7076 139+#if !defined(NO_ERRNO) && __DARWIN_UNIX03
34e8f829
A
140 errno = ERANGE;
141 #endif
142 }
1f2f436a 143@@ -1047,7 +1072,7 @@ strtodg
34e8f829
A
144 (rvb->wds > 0 ? STRTOG_Denormal : STRTOG_Zero);
145 if (irv & STRTOG_Inexact) {
146 irv |= STRTOG_Underflow;
147-#ifndef NO_ERRNO
148+#if !defined(NO_ERRNO) && __DARWIN_UNIX03
149 errno = ERANGE;
150 #endif
151 }
1f2f436a
A
152@@ -1061,5 +1086,11 @@ strtodg
153 copybits(bits, nbits, rvb);
154 Bfree(rvb);
155 }
156+ if (strunc)
157+#ifdef FREE
158+ FREE(strunc);
159+#else
160+ free(strunc);
161+#endif
162 return irv;
163 }