- char part[LOCALE_NAME_MAX+1];
- if (name[0] && name[1]==';'
- && strlen(name) > 2 + 3*(LOCALE_NAME_MAX+1)) {
- part[0] = name[0];
- part[1] = 0;
- setlocale(LC_CTYPE, part);
- part[LOCALE_NAME_MAX] = 0;
- for (i=LC_TIME; i<LC_MESSAGES; i++) {
- memcpy(part, name + 2 + (i-2)*(LOCALE_NAME_MAX+1), LOCALE_NAME_MAX);
- for (j=LOCALE_NAME_MAX-1; j && part[j]==';'; j--)
- part[j] = 0;
- setlocale(i, part);
+ struct __locale_struct tmp_locale;
+ char part[LOCALE_NAME_MAX+1] = "C.UTF-8";
+ const char *p = name;
+ for (i=0; i<LC_ALL; i++) {
+ const char *z = __strchrnul(p, ';');
+ if (z-p <= LOCALE_NAME_MAX) {
+ memcpy(part, p, z-p);
+ part[z-p] = 0;
+ if (*z) p = z+1;
+ }
+ lm = __get_locale(i, part);
+ if (lm == LOC_MAP_FAILED) {
+ UNLOCK(lock);
+ return 0;