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

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

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 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
OLDNEW
1 #include <locale.h> 1 #include <locale.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <string.h> 3 #include <string.h>
4 #include "locale_impl.h" 4 #include "locale_impl.h"
5 #include "libc.h" 5 #include "libc.h"
6 #include "atomic.h" 6 #include "atomic.h"
7 7
8 static char buf[LC_ALL*(LOCALE_NAME_MAX+1)]; 8 static char buf[LC_ALL * (LOCALE_NAME_MAX + 1)];
9 9
10 static char *setlocale_one_unlocked(int cat, const char *name) 10 static char* setlocale_one_unlocked(int cat, const char* name) {
11 { 11 const struct __locale_map* lm;
12 » const struct __locale_map *lm;
13 12
14 » if (name) libc.global_locale.cat[cat] = lm = __get_locale(cat, name); 13 if (name)
15 » else lm = libc.global_locale.cat[cat]; 14 libc.global_locale.cat[cat] = lm = __get_locale(cat, name);
15 else
16 lm = libc.global_locale.cat[cat];
16 17
17 » return lm ? (char *)lm->name : "C"; 18 return lm ? (char*)lm->name : "C";
18 } 19 }
19 20
20 char *__strchrnul(const char *, int); 21 char* __strchrnul(const char*, int);
21 22
22 char *setlocale(int cat, const char *name) 23 char* setlocale(int cat, const char* name) {
23 { 24 static volatile int lock[2];
24 » static volatile int lock[2];
25 25
26 » if ((unsigned)cat > LC_ALL) return 0; 26 if ((unsigned)cat > LC_ALL)
27 return 0;
27 28
28 » LOCK(lock); 29 LOCK(lock);
29 30
30 » /* For LC_ALL, setlocale is required to return a string which 31 /* For LC_ALL, setlocale is required to return a string which
31 » * encodes the current setting for all categories. The format of 32 * encodes the current setting for all categories. The format of
32 » * this string is unspecified, and only the following code, which 33 * this string is unspecified, and only the following code, which
33 » * performs both the serialization and deserialization, depends 34 * performs both the serialization and deserialization, depends
34 » * on the format, so it can easily be changed if needed. */ 35 * on the format, so it can easily be changed if needed. */
35 » if (cat == LC_ALL) { 36 if (cat == LC_ALL) {
36 » » int i; 37 int i;
37 » » if (name) { 38 if (name) {
38 » » » char part[LOCALE_NAME_MAX+1] = "C.UTF-8"; 39 char part[LOCALE_NAME_MAX + 1] = "C.UTF-8";
39 » » » const char *p = name; 40 const char* p = name;
40 » » » for (i=0; i<LC_ALL; i++) { 41 for (i = 0; i < LC_ALL; i++) {
41 » » » » const char *z = __strchrnul(p, ';'); 42 const char* z = __strchrnul(p, ';');
42 » » » » if (z-p <= LOCALE_NAME_MAX) { 43 if (z - p <= LOCALE_NAME_MAX) {
43 » » » » » memcpy(part, p, z-p); 44 memcpy(part, p, z - p);
44 » » » » » part[z-p] = 0; 45 part[z - p] = 0;
45 » » » » » if (*z) p = z+1; 46 if (*z)
46 » » » » } 47 p = z + 1;
47 » » » » setlocale_one_unlocked(i, part); 48 }
48 » » » } 49 setlocale_one_unlocked(i, part);
49 » » } 50 }
50 » » char *s = buf; 51 }
51 » » for (i=0; i<LC_ALL; i++) { 52 char* s = buf;
52 » » » const struct __locale_map *lm = 53 for (i = 0; i < LC_ALL; i++) {
53 » » » » libc.global_locale.cat[i]; 54 const struct __locale_map* lm = libc.global_locale.cat[i];
54 » » » const char *part = lm ? lm->name : "C"; 55 const char* part = lm ? lm->name : "C";
55 » » » size_t l = strlen(part); 56 size_t l = strlen(part);
56 » » » memcpy(s, part, l); 57 memcpy(s, part, l);
57 » » » s[l] = ';'; 58 s[l] = ';';
58 » » » s += l+1; 59 s += l + 1;
59 » » } 60 }
60 » » *--s = 0; 61 *--s = 0;
61 » » UNLOCK(lock); 62 UNLOCK(lock);
62 » » return buf; 63 return buf;
63 » } 64 }
64 65
65 » char *ret = setlocale_one_unlocked(cat, name); 66 char* ret = setlocale_one_unlocked(cat, name);
66 67
67 » UNLOCK(lock); 68 UNLOCK(lock);
68 69
69 » return ret; 70 return ret;
70 } 71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698