@@ -137,6 +137,9 @@ template <class charT> class messages_byname;
137
137
#include < streambuf>
138
138
#include < iterator>
139
139
#include < limits>
140
+ #if !__APPLE__
141
+ #include < cstdarg>
142
+ #endif
140
143
#include < cstdlib>
141
144
#include < ctime>
142
145
#include < nl_types.h>
@@ -145,6 +148,131 @@ template <class charT> class messages_byname;
145
148
146
149
_LIBCPP_BEGIN_NAMESPACE_STD
147
150
151
+ // OSX has nice foo_l() functions that let you turn off use of the global
152
+ // locale. Linux, not so much. The following functions avoid the locale when
153
+ // that's possible and otherwise do the wrong thing. FIXME.
154
+ #if __APPLE__
155
+
156
+ template <class _Tp >
157
+ inline
158
+ int
159
+ __nolocale_sprintf (char * __restrict __str,
160
+ const char * __restrict __format, _Tp __v)
161
+ {
162
+ return sprintf_l (__str, 0 , __format, __v);
163
+ }
164
+
165
+ template <class _Tp >
166
+ inline
167
+ int
168
+ __nolocale_snprintf (char * __restrict __str, size_t __size,
169
+ const char * __restrict __format, _Tp __v)
170
+ {
171
+ return snprintf_l (__str, __size, 0 , __format, __v);
172
+ }
173
+
174
+ template <class _Tp >
175
+ inline
176
+ int
177
+ __nolocale_snprintf (char * __restrict __str, size_t __size,
178
+ const char * __restrict __format, int __prec, _Tp __v)
179
+ {
180
+ return snprintf_l (__str, __size, 0 , __format, __prec, __v);
181
+ }
182
+
183
+ template <class _Tp >
184
+ inline
185
+ int
186
+ __nolocale_asprintf (char ** __ret, const char * __restrict __format, _Tp __v)
187
+ {
188
+ return asprintf_l (__ret, 0 , __format, __v);
189
+ }
190
+
191
+ template <class _Tp >
192
+ inline
193
+ int
194
+ __nolocale_asprintf (char ** __ret, const char * __restrict __format, int __prec,
195
+ _Tp __v)
196
+ {
197
+ return asprintf_l (__ret, 0 , __format, __prec, __v);
198
+ }
199
+
200
+ template <class _Tp >
201
+ inline
202
+ int
203
+ __nolocale_sscanf (const char * __restrict __str,
204
+ const char * __restrict __format, _Tp* __v)
205
+ {
206
+ return sscanf_l (__str, 0 , __format, __v);
207
+ }
208
+
209
+ inline
210
+ int
211
+ __nolocale_isxdigit (int __c)
212
+ {
213
+ return isxdigit_l (__c, 0 );
214
+ }
215
+
216
+ inline
217
+ int
218
+ __nolocale_isdigit (int __c)
219
+ {
220
+ return isdigit_l (__c, 0 );
221
+ }
222
+
223
+ #else /* !__APPLE__ */
224
+ inline int
225
+ __nolocale_sprintf (char * __restrict __str,
226
+ const char * __restrict __format, ...)
227
+ {
228
+ va_list __ap;
229
+ va_start (__ap, __format);
230
+ int __result = vsprintf (__str, __format, __ap);
231
+ va_end (__ap);
232
+ return __result;
233
+ }
234
+ inline int
235
+ __nolocale_snprintf (char * __restrict __str, size_t __size,
236
+ const char * __restrict __format, ...)
237
+ {
238
+ va_list __ap;
239
+ va_start (__ap, __format);
240
+ int __result = vsnprintf (__str, __size, __format, __ap);
241
+ va_end (__ap);
242
+ return __result;
243
+ }
244
+ inline int
245
+ __nolocale_asprintf (char ** __ret,
246
+ const char * __restrict __format, ...)
247
+ {
248
+ va_list __ap;
249
+ va_start (__ap, __format);
250
+ int __result = vasprintf (__ret, __format, __ap);
251
+ va_end (__ap);
252
+ return __result;
253
+ }
254
+ inline int
255
+ __nolocale_sscanf (const char * __restrict __str,
256
+ const char * __restrict __format, ...)
257
+ {
258
+ va_list __ap;
259
+ va_start (__ap, __format);
260
+ int __result = vsscanf (__str, __format, __ap);
261
+ va_end (__ap);
262
+ return __result;
263
+ }
264
+ inline int
265
+ __nolocale_isxdigit (int __c)
266
+ {
267
+ return isxdigit (__c);
268
+ }
269
+ inline int
270
+ __nolocale_isdigit (int __c)
271
+ {
272
+ return isdigit (__c);
273
+ }
274
+ #endif /* __APPLE__ */
275
+
148
276
// __scan_keyword
149
277
// Scans [__b, __e) until a match is found in the basic_strings range
150
278
// [__kb, __ke) or until it can be shown that there is no match in [__kb, __ke).
@@ -1002,7 +1130,7 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
1002
1130
break ;
1003
1131
// Stage 3
1004
1132
__a[sizeof (__a)-1 ] = 0 ;
1005
- if (sscanf_l (__a, 0 , " %p" , &__v) != 1 )
1133
+ if (__nolocale_sscanf (__a, " %p" , &__v) != 1 )
1006
1134
__err = ios_base::failbit;
1007
1135
// EOF checked
1008
1136
if (__b == __e)
@@ -1107,13 +1235,13 @@ __num_put<_CharT>::__widen_and_group_float(char* __nb, char* __np, char* __ne,
1107
1235
*__oe++ = __ct.widen (*__nf++);
1108
1236
*__oe++ = __ct.widen (*__nf++);
1109
1237
for (__ns = __nf; __ns < __ne; ++__ns)
1110
- if (!isxdigit_l (*__ns, 0 ))
1238
+ if (!__nolocale_isxdigit (*__ns))
1111
1239
break ;
1112
1240
}
1113
1241
else
1114
1242
{
1115
1243
for (__ns = __nf; __ns < __ne; ++__ns)
1116
- if (!isdigit_l (*__ns, 0 ))
1244
+ if (!__nolocale_isdigit (*__ns))
1117
1245
break ;
1118
1246
}
1119
1247
if (__grouping.empty ())
@@ -1310,7 +1438,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1310
1438
+ ((numeric_limits<long >::digits % 3 ) != 0 )
1311
1439
+ 1 ;
1312
1440
char __nar[__nbuf];
1313
- int __nc = sprintf_l (__nar, 0 , __fmt, __v);
1441
+ int __nc = __nolocale_sprintf (__nar, __fmt, __v);
1314
1442
char * __ne = __nar + __nc;
1315
1443
char * __np = this ->__identify_padding (__nar, __ne, __iob);
1316
1444
// Stage 2 - Widen __nar while adding thousands separators
@@ -1336,7 +1464,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1336
1464
+ ((numeric_limits<long long >::digits % 3 ) != 0 )
1337
1465
+ 1 ;
1338
1466
char __nar[__nbuf];
1339
- int __nc = sprintf_l (__nar, 0 , __fmt, __v);
1467
+ int __nc = __nolocale_sprintf (__nar, __fmt, __v);
1340
1468
char * __ne = __nar + __nc;
1341
1469
char * __np = this ->__identify_padding (__nar, __ne, __iob);
1342
1470
// Stage 2 - Widen __nar while adding thousands separators
@@ -1362,7 +1490,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1362
1490
+ ((numeric_limits<unsigned long >::digits % 3 ) != 0 )
1363
1491
+ 1 ;
1364
1492
char __nar[__nbuf];
1365
- int __nc = sprintf_l (__nar, 0 , __fmt, __v);
1493
+ int __nc = __nolocale_sprintf (__nar, __fmt, __v);
1366
1494
char * __ne = __nar + __nc;
1367
1495
char * __np = this ->__identify_padding (__nar, __ne, __iob);
1368
1496
// Stage 2 - Widen __nar while adding thousands separators
@@ -1388,7 +1516,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1388
1516
+ ((numeric_limits<unsigned long long >::digits % 3 ) != 0 )
1389
1517
+ 1 ;
1390
1518
char __nar[__nbuf];
1391
- int __nc = sprintf_l (__nar, 0 , __fmt, __v);
1519
+ int __nc = __nolocale_sprintf (__nar, __fmt, __v);
1392
1520
char * __ne = __nar + __nc;
1393
1521
char * __np = this ->__identify_padding (__nar, __ne, __iob);
1394
1522
// Stage 2 - Widen __nar while adding thousands separators
@@ -1415,16 +1543,18 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1415
1543
char * __nb = __nar;
1416
1544
int __nc;
1417
1545
if (__specify_precision)
1418
- __nc = snprintf_l (__nb, __nbuf, 0 , __fmt, (int )__iob.precision (), __v);
1546
+ __nc = __nolocale_snprintf (__nb, __nbuf, __fmt,
1547
+ (int )__iob.precision (), __v);
1419
1548
else
1420
- __nc = snprintf_l (__nb, __nbuf, 0 , __fmt, __v);
1549
+ __nc = __nolocale_snprintf (__nb, __nbuf, __fmt, __v);
1421
1550
unique_ptr<char , void (*)(void *)> __nbh (0 , free);
1422
1551
if (__nc > static_cast <int >(__nbuf-1 ))
1423
1552
{
1424
1553
if (__specify_precision)
1425
- __nc = asprintf_l (&__nb, 0 , __fmt, (int )__iob.precision (), __v);
1554
+ __nc = __nolocale_asprintf (&__nb, __fmt, (int )__iob.precision (),
1555
+ __v);
1426
1556
else
1427
- __nc = asprintf_l (&__nb, 0 , __fmt, __v);
1557
+ __nc = __nolocale_asprintf (&__nb, __fmt, __v);
1428
1558
if (__nb == 0 )
1429
1559
__throw_bad_alloc ();
1430
1560
__nbh.reset (__nb);
@@ -1465,16 +1595,18 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1465
1595
char * __nb = __nar;
1466
1596
int __nc;
1467
1597
if (__specify_precision)
1468
- __nc = snprintf_l (__nb, __nbuf, 0 , __fmt, (int )__iob.precision (), __v);
1598
+ __nc = __nolocale_snprintf (__nb, __nbuf, __fmt,
1599
+ (int )__iob.precision (), __v);
1469
1600
else
1470
- __nc = snprintf_l (__nb, __nbuf, 0 , __fmt, __v);
1601
+ __nc = __nolocale_snprintf (__nb, __nbuf, __fmt, __v);
1471
1602
unique_ptr<char , void (*)(void *)> __nbh (0 , free);
1472
1603
if (__nc > static_cast <int >(__nbuf-1 ))
1473
1604
{
1474
1605
if (__specify_precision)
1475
- __nc = asprintf_l (&__nb, 0 , __fmt, (int )__iob.precision (), __v);
1606
+ __nc = __nolocale_asprintf (&__nb, __fmt, (int )__iob.precision (),
1607
+ __v);
1476
1608
else
1477
- __nc = asprintf_l (&__nb, 0 , __fmt, __v);
1609
+ __nc = __nolocale_asprintf (&__nb, __fmt, __v);
1478
1610
if (__nb == 0 )
1479
1611
__throw_bad_alloc ();
1480
1612
__nbh.reset (__nb);
@@ -1510,7 +1642,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
1510
1642
char __fmt[6 ] = " %p" ;
1511
1643
const unsigned __nbuf = 20 ;
1512
1644
char __nar[__nbuf];
1513
- int __nc = sprintf_l (__nar, 0 , __fmt, __v);
1645
+ int __nc = __nolocale_sprintf (__nar, __fmt, __v);
1514
1646
char * __ne = __nar + __nc;
1515
1647
char * __np = this ->__identify_padding (__nar, __ne, __iob);
1516
1648
// Stage 2 - Widen __nar
@@ -3162,7 +3294,7 @@ money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl,
3162
3294
// secure memory for digit storage
3163
3295
if (__n > __bs-1 )
3164
3296
{
3165
- __n = asprintf_l (&__bb, 0 , " %.0Lf" , __units);
3297
+ __n = __nolocale_asprintf (&__bb, " %.0Lf" , __units);
3166
3298
if (__bb == 0 )
3167
3299
__throw_bad_alloc ();
3168
3300
__hn.reset (__bb);
0 commit comments