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

Side by Side Diff: fusl/src/stdio/fgetwc.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 "stdio_impl.h" 1 #include "stdio_impl.h"
2 #include "locale_impl.h" 2 #include "locale_impl.h"
3 #include <wchar.h> 3 #include <wchar.h>
4 #include <errno.h> 4 #include <errno.h>
5 5
6 static wint_t __fgetwc_unlocked_internal(FILE *f) 6 static wint_t __fgetwc_unlocked_internal(FILE* f) {
7 { 7 mbstate_t st = {0};
8 » mbstate_t st = { 0 }; 8 wchar_t wc;
9 » wchar_t wc; 9 int c;
10 » int c; 10 unsigned char b;
11 » unsigned char b; 11 size_t l;
12 » size_t l;
13 12
14 » /* Convert character from buffer if possible */ 13 /* Convert character from buffer if possible */
15 » if (f->rpos < f->rend) { 14 if (f->rpos < f->rend) {
16 » » l = mbrtowc(&wc, (void *)f->rpos, f->rend - f->rpos, &st); 15 l = mbrtowc(&wc, (void*)f->rpos, f->rend - f->rpos, &st);
17 » » if (l+2 >= 2) { 16 if (l + 2 >= 2) {
18 » » » f->rpos += l + !l; /* l==0 means 1 byte, null */ 17 f->rpos += l + !l; /* l==0 means 1 byte, null */
19 » » » return wc; 18 return wc;
20 » » } 19 }
21 » » if (l == -1) { 20 if (l == -1) {
22 » » » f->rpos++; 21 f->rpos++;
23 » » » return WEOF; 22 return WEOF;
24 » » } 23 }
25 » } else l = -2; 24 } else
25 l = -2;
26 26
27 » /* Convert character byte-by-byte */ 27 /* Convert character byte-by-byte */
28 » while (l == -2) { 28 while (l == -2) {
29 » » b = c = getc_unlocked(f); 29 b = c = getc_unlocked(f);
30 » » if (c < 0) { 30 if (c < 0) {
31 » » » if (!mbsinit(&st)) errno = EILSEQ; 31 if (!mbsinit(&st))
32 » » » return WEOF; 32 errno = EILSEQ;
33 » » } 33 return WEOF;
34 » » l = mbrtowc(&wc, (void *)&b, 1, &st); 34 }
35 » » if (l == -1) return WEOF; 35 l = mbrtowc(&wc, (void*)&b, 1, &st);
36 » } 36 if (l == -1)
37 return WEOF;
38 }
37 39
38 » return wc; 40 return wc;
39 } 41 }
40 42
41 wint_t __fgetwc_unlocked(FILE *f) 43 wint_t __fgetwc_unlocked(FILE* f) {
42 { 44 locale_t *ploc = &CURRENT_LOCALE, loc = *ploc;
43 » locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; 45 if (f->mode <= 0)
44 » if (f->mode <= 0) fwide(f, 1); 46 fwide(f, 1);
45 » *ploc = f->locale; 47 *ploc = f->locale;
46 » wchar_t wc = __fgetwc_unlocked_internal(f); 48 wchar_t wc = __fgetwc_unlocked_internal(f);
47 » *ploc = loc; 49 *ploc = loc;
48 » return wc; 50 return wc;
49 } 51 }
50 52
51 wint_t fgetwc(FILE *f) 53 wint_t fgetwc(FILE* f) {
52 { 54 wint_t c;
53 » wint_t c; 55 FLOCK(f);
54 » FLOCK(f); 56 c = __fgetwc_unlocked(f);
55 » c = __fgetwc_unlocked(f); 57 FUNLOCK(f);
56 » FUNLOCK(f); 58 return c;
57 » return c;
58 } 59 }
59 60
60 weak_alias(__fgetwc_unlocked, fgetwc_unlocked); 61 weak_alias(__fgetwc_unlocked, fgetwc_unlocked);
61 weak_alias(__fgetwc_unlocked, getwc_unlocked); 62 weak_alias(__fgetwc_unlocked, getwc_unlocked);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698