+ /* Otherwise, first see if we can use one of the builtin locales.
+ * This makes the common usage case for newlocale, getting a C locale
+ * with predictable behavior, very fast, and more importantly, fail-safe. */
+ if (!memcmp(&tmp, C_LOCALE, sizeof tmp)) return C_LOCALE;
+ if (!memcmp(&tmp, UTF8_LOCALE, sizeof tmp)) return UTF8_LOCALE;
+
+ /* And provide builtins for the initial default locale, and a
+ * variant of the C locale honoring the default locale's encoding. */
+ pthread_once(&default_locale_once, default_locale_init);
+ if (!memcmp(&tmp, &default_locale, sizeof tmp)) return &default_locale;
+ if (!memcmp(&tmp, &default_ctype_locale, sizeof tmp))
+ return &default_ctype_locale;
+
+ /* If no builtin locale matched, attempt to allocate and copy. */
+ if ((loc = malloc(sizeof *loc))) *loc = tmp;