overhaul locale internals to treat categories roughly uniformly
[musl] / src / locale / newlocale.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include "locale_impl.h"
4 #include "libc.h"
5
6 locale_t __newlocale(int mask, const char *name, locale_t loc)
7 {
8         int i;
9
10         if (!loc) {
11                 loc = malloc(sizeof *loc);
12                 if (!loc) return 0;
13                 for (i=0; i<LC_ALL; i++)
14                         if (!(mask & (1<<i)))
15                                 loc->cat[i] = __get_locale(i, "");
16         }
17
18         for (i=0; i<LC_ALL; i++)
19                 if (mask & (1<<i))
20                         loc->cat[i] = __get_locale(i, name);
21
22         return loc;
23 }
24
25 weak_alias(__newlocale, newlocale);