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

Unified Diff: fusl/src/multibyte/mbrtowc.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 side-by-side diff with in-line comments
Download patch
Index: fusl/src/multibyte/mbrtowc.c
diff --git a/fusl/src/multibyte/mbrtowc.c b/fusl/src/multibyte/mbrtowc.c
index ca7da700ed7f0ec7d4b34d982625b8cb7bef0ee5..8bd49ec886963675358164e929bb2557da880d31 100644
--- a/fusl/src/multibyte/mbrtowc.c
+++ b/fusl/src/multibyte/mbrtowc.c
@@ -1,4 +1,4 @@
-/*
+/*
* This code was written by Rich Felker in 2010; no copyright is claimed.
* This code is in the public domain. Attribution is appreciated but
* unnecessary.
@@ -9,49 +9,62 @@
#include <errno.h>
#include "internal.h"
-size_t mbrtowc(wchar_t *restrict wc, const char *restrict src, size_t n, mbstate_t *restrict st)
-{
- static unsigned internal_state;
- unsigned c;
- const unsigned char *s = (const void *)src;
- const unsigned N = n;
- wchar_t dummy;
+size_t mbrtowc(wchar_t* restrict wc,
+ const char* restrict src,
+ size_t n,
+ mbstate_t* restrict st) {
+ static unsigned internal_state;
+ unsigned c;
+ const unsigned char* s = (const void*)src;
+ const unsigned N = n;
+ wchar_t dummy;
- if (!st) st = (void *)&internal_state;
- c = *(unsigned *)st;
-
- if (!s) {
- if (c) goto ilseq;
- return 0;
- } else if (!wc) wc = &dummy;
+ if (!st)
+ st = (void*)&internal_state;
+ c = *(unsigned*)st;
- if (!n) return -2;
- if (!c) {
- if (*s < 0x80) return !!(*wc = *s);
- if (MB_CUR_MAX==1) return (*wc = CODEUNIT(*s)), 1;
- if (*s-SA > SB-SA) goto ilseq;
- c = bittab[*s++-SA]; n--;
- }
+ if (!s) {
+ if (c)
+ goto ilseq;
+ return 0;
+ } else if (!wc)
+ wc = &dummy;
- if (n) {
- if (OOB(c,*s)) goto ilseq;
-loop:
- c = c<<6 | *s++-0x80; n--;
- if (!(c&(1U<<31))) {
- *(unsigned *)st = 0;
- *wc = c;
- return N-n;
- }
- if (n) {
- if (*s-0x80u >= 0x40) goto ilseq;
- goto loop;
- }
- }
+ if (!n)
+ return -2;
+ if (!c) {
+ if (*s < 0x80)
+ return !!(*wc = *s);
+ if (MB_CUR_MAX == 1)
+ return (*wc = CODEUNIT(*s)), 1;
+ if (*s - SA > SB - SA)
+ goto ilseq;
+ c = bittab[*s++ - SA];
+ n--;
+ }
- *(unsigned *)st = c;
- return -2;
+ if (n) {
+ if (OOB(c, *s))
+ goto ilseq;
+ loop:
+ c = c << 6 | *s++ - 0x80;
+ n--;
+ if (!(c & (1U << 31))) {
+ *(unsigned*)st = 0;
+ *wc = c;
+ return N - n;
+ }
+ if (n) {
+ if (*s - 0x80u >= 0x40)
+ goto ilseq;
+ goto loop;
+ }
+ }
+
+ *(unsigned*)st = c;
+ return -2;
ilseq:
- *(unsigned *)st = 0;
- errno = EILSEQ;
- return -1;
+ *(unsigned*)st = 0;
+ errno = EILSEQ;
+ return -1;
}

Powered by Google App Engine
This is Rietveld 408576698