mailing list of musl libc
 help / color / mirror / code / Atom feed
* [setlocale]: return only one copy if all six parts of locale are same
@ 2017-03-18  7:37 He X
  2017-03-18 12:33 ` Rich Felker
  0 siblings, 1 reply; 6+ messages in thread
From: He X @ 2017-03-18  7:37 UTC (permalink / raw)
  To: musl


[-- Attachment #1.1: Type: text/plain, Size: 39 bytes --]

As i suggest on IRC, here's the patch.

[-- Attachment #1.2: Type: text/html, Size: 64 bytes --]

[-- Attachment #2: setlocale.diff --]
[-- Type: text/plain, Size: 1037 bytes --]

--- 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;
 	}

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-03-18 15:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-18  7:37 [setlocale]: return only one copy if all six parts of locale are same He X
2017-03-18 12:33 ` Rich Felker
2017-03-18 13:36   ` He X
2017-03-18 13:48     ` He X
2017-03-18 14:39       ` Rich Felker
2017-03-18 15:00         ` He X

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).