Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(681)

Side by Side Diff: fusl/src/locale/newlocale.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fusl/src/locale/localeconv.c ('k') | fusl/src/locale/pleval.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include <stdlib.h>
2 #include <string.h>
3 #include "locale_impl.h"
4 #include "libc.h"
5
6 int __loc_is_allocated(locale_t loc)
7 {
8 return loc && loc != C_LOCALE && loc != UTF8_LOCALE;
9 }
10
11 locale_t __newlocale(int mask, const char *name, locale_t loc)
12 {
13 int i, j;
14 struct __locale_struct tmp;
15 const struct __locale_map *lm;
16
17 /* For locales with allocated storage, modify in-place. */
18 if (__loc_is_allocated(loc)) {
19 for (i=0; i<LC_ALL; i++)
20 if (mask & (1<<i))
21 loc->cat[i] = __get_locale(i, name);
22 return loc;
23 }
24
25 /* Otherwise, build a temporary locale object, which will only
26 * be instantiated in allocated storage if it does not match
27 * one of the built-in static locales. This makes the common
28 * usage case for newlocale, getting a C locale with predictable
29 * behavior, very fast, and more importantly, fail-safe. */
30 for (j=i=0; i<LC_ALL; i++) {
31 if (loc && !(mask & (1<<i)))
32 lm = loc->cat[i];
33 else
34 lm = __get_locale(i, mask & (1<<i) ? name : "");
35 if (lm) j++;
36 tmp.cat[i] = lm;
37 }
38
39 if (!j)
40 return C_LOCALE;
41 if (j==1 && tmp.cat[LC_CTYPE]==&__c_dot_utf8)
42 return UTF8_LOCALE;
43
44 if ((loc = malloc(sizeof *loc))) *loc = tmp;
45
46 return loc;
47 }
48
49 weak_alias(__newlocale, newlocale);
OLDNEW
« no previous file with comments | « fusl/src/locale/localeconv.c ('k') | fusl/src/locale/pleval.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698