--- musl-1.1.16/src/locale/setlocale.c	2017-03-17 17:49:15.767952411 +0000
+++ musl-1.1.16/src/locale/setlocale.c	2017-03-17 17:49:15.767952411 +0000
@@ -48,16 +48,33 @@
 			}
 		}
 		char *s = buf;
-		for (i=0; i<LC_ALL; i++) {
+ 		const struct __locale_map *flm =
+ 			libc.global_locale.cat[0];
+ 		const char *fpart = flm ? flm->name : "C";
+ 		size_t l = strlen(fpart);
+ 		memcpy(s, fpart, l);
+ 		s[l] = 0;
+ 		i=1;
+ 		do {
 			const struct __locale_map *lm =
 				libc.global_locale.cat[i];
 			const char *part = lm ? lm->name : "C";
-			size_t l = strlen(part);
-			memcpy(s, part, l);
-			s[l] = ';';
-			s += l+1;
+ 			if (strcmp(s, part)) break;
+ 			i++;
+ 		} while (i<LC_ALL);
+ 
+ 		if (i != LC_ALL) {
+ 			for (i=0; i<LC_ALL; i++) {
+ 				const struct __locale_map *lm =
+ 					libc.global_locale.cat[i];
+ 				const char *part = lm ? lm->name : "C";
+ 				size_t l = strlen(part);
+ 				memcpy(s, part, l);
+ 				s[l] = ';';
+ 				s += l+1;
+ 			}
+ 			*--s = 0;
 		}
-		*--s = 0;
 		UNLOCK(lock);
 		return buf;
 	}