From: He X <xw897002528@gmail.com>
To: musl@lists.openwall.com
Subject: [setlocale]: return only one copy if all six parts of locale are same
Date: Sat, 18 Mar 2017 07:37:57 +0000 [thread overview]
Message-ID: <CAPG2z0-d6_3fOx408S1vxbjTuLuKRGd5JK++_BfoX3K-Ct8-5w@mail.gmail.com> (raw)
[-- 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;
}
next reply other threads:[~2017-03-18 7:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-18 7:37 He X [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPG2z0-d6_3fOx408S1vxbjTuLuKRGd5JK++_BfoX3K-Ct8-5w@mail.gmail.com \
--to=xw897002528@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).