+/*
+ * PRIVATE EXTERNAL: Returns the locale that can be used by wcstod and
+ * family, to convert the wide character string to a multi-byte string
+ * (the LC_NUMERIC and LC_CTYPE locales may be different).
+ */
+__private_extern__ locale_t
+__numeric_ctype(locale_t loc)
+{
+ switch(loc->__numeric_fp_cvt) {
+ case LC_NUMERIC_FP_UNINITIALIZED: {
+ const char *ctype = loc->__lc_ctype->__ctype_encoding;
+ const char *numeric = (loc->_numeric_using_locale ? loc->__lc_numeric->_numeric_locale_buf : C);
+ if (strcmp(ctype, numeric) == 0) {
+ loc->__numeric_fp_cvt = LC_NUMERIC_FP_SAME_LOCALE;
+ return loc;
+ } else {
+ loc->__lc_numeric_loc = newlocale(LC_CTYPE_MASK, numeric, &__c_locale);
+ if (loc->__lc_numeric_loc) {
+ loc->__numeric_fp_cvt = LC_NUMERIC_FP_USE_LOCALE;
+ return loc->__lc_numeric_loc;
+ } else { /* shouldn't happen, but just use the same locale */
+ loc->__numeric_fp_cvt = LC_NUMERIC_FP_SAME_LOCALE;
+ return loc;
+ }
+ }
+ }
+ case LC_NUMERIC_FP_SAME_LOCALE:
+ return loc;
+ case LC_NUMERIC_FP_USE_LOCALE:
+ return loc->__lc_numeric_loc;
+ }
+ return loc; /* shouldn't happen */
+}
+