~_Save_errno() { if (errno == 0) errno = _M_errno; }
int _M_errno;
};
+
+ // calls setlocale(LC_ALL, "C") and returns a string containing the old
+ // locale name. Caller must delete[] the string. Returns NULL on error.
+ const char*
+ __set_C_locale()
+ {
+ char* __old = setlocale(LC_ALL, 0);
+ const size_t __len = strlen(__old) + 1;
+ char* __sav = new(nothrow) char[__len];
+ if (__sav)
+ {
+ memcpy(__sav, __old, __len);
+ setlocale(LC_ALL, "C");
+ }
+ return __sav;
+ }
}
template<>
const __c_locale&) throw()
{
// Assumes __s formatted for "C" locale.
- char* __old = setlocale(LC_ALL, 0);
- const size_t __len = strlen(__old) + 1;
- char* __sav = new char[__len];
- memcpy(__sav, __old, __len);
- setlocale(LC_ALL, "C");
+ const char* __sav = __set_C_locale();
+ if (!__sav)
+ {
+ __err = ios_base::failbit;
+ return;
+ }
char* __sanity;
bool __overflow = false;
const __c_locale&) throw()
{
// Assumes __s formatted for "C" locale.
- char* __old = setlocale(LC_ALL, 0);
- const size_t __len = strlen(__old) + 1;
- char* __sav = new char[__len];
- memcpy(__sav, __old, __len);
- setlocale(LC_ALL, "C");
+ const char* __sav = __set_C_locale();
+ if (!__sav)
+ {
+ __err = ios_base::failbit;
+ return;
+ }
char* __sanity;
#if !__DBL_HAS_INFINITY__
ios_base::iostate& __err, const __c_locale&) throw()
{
// Assumes __s formatted for "C" locale.
- char* __old = setlocale(LC_ALL, 0);
- const size_t __len = strlen(__old) + 1;
- char* __sav = new char[__len];
- memcpy(__sav, __old, __len);
- setlocale(LC_ALL, "C");
+ const char* __sav = __set_C_locale();
+ if (!__sav)
+ {
+ __err = ios_base::failbit;
+ return;
+ }
#if !__LDBL_HAS_INFINITY__
const _Save_errno __save_errno;