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

Side by Side Diff: fusl/src/stdio/vswprintf.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 <limits.h> 2 #include <limits.h>
3 #include <string.h> 3 #include <string.h>
4 #include <errno.h> 4 #include <errno.h>
5 #include <stdint.h> 5 #include <stdint.h>
6 #include <wchar.h> 6 #include <wchar.h>
7 7
8 struct cookie { 8 struct cookie {
9 » wchar_t *ws; 9 wchar_t* ws;
10 » size_t l; 10 size_t l;
11 }; 11 };
12 12
13 static size_t sw_write(FILE *f, const unsigned char *s, size_t l) 13 static size_t sw_write(FILE* f, const unsigned char* s, size_t l) {
14 { 14 size_t l0 = l;
15 » size_t l0 = l; 15 int i = 0;
16 » int i = 0; 16 struct cookie* c = f->cookie;
17 » struct cookie *c = f->cookie; 17 if (s != f->wbase && sw_write(f, f->wbase, f->wpos - f->wbase) == -1)
18 » if (s!=f->wbase && sw_write(f, f->wbase, f->wpos-f->wbase)==-1) 18 return -1;
19 » » return -1; 19 while (c->l && l && (i = mbtowc(c->ws, (void*)s, l)) >= 0) {
20 » while (c->l && l && (i=mbtowc(c->ws, (void *)s, l))>=0) { 20 s += i;
21 » » s+=i; 21 l -= i;
22 » » l-=i; 22 c->l--;
23 » » c->l--; 23 c->ws++;
24 » » c->ws++; 24 }
25 » } 25 *c->ws = 0;
26 » *c->ws = 0; 26 return i < 0 ? i : l0;
27 » return i<0 ? i : l0;
28 } 27 }
29 28
30 int vswprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, va_lis t ap) 29 int vswprintf(wchar_t* restrict s,
31 { 30 size_t n,
32 » int r; 31 const wchar_t* restrict fmt,
33 » FILE f; 32 va_list ap) {
34 » unsigned char buf[256]; 33 int r;
35 » struct cookie c = { s, n-1 }; 34 FILE f;
35 unsigned char buf[256];
36 struct cookie c = {s, n - 1};
36 37
37 » memset(&f, 0, sizeof(FILE)); 38 memset(&f, 0, sizeof(FILE));
38 » f.lbf = EOF; 39 f.lbf = EOF;
39 » f.write = sw_write; 40 f.write = sw_write;
40 » f.buf_size = sizeof buf; 41 f.buf_size = sizeof buf;
41 » f.buf = buf; 42 f.buf = buf;
42 » f.lock = -1; 43 f.lock = -1;
43 » f.cookie = &c; 44 f.cookie = &c;
44 » if (!n) { 45 if (!n) {
45 » » return -1; 46 return -1;
46 » } else if (n > INT_MAX) { 47 } else if (n > INT_MAX) {
47 » » errno = EOVERFLOW; 48 errno = EOVERFLOW;
48 » » return -1; 49 return -1;
49 » } 50 }
50 » r = vfwprintf(&f, fmt, ap); 51 r = vfwprintf(&f, fmt, ap);
51 » sw_write(&f, 0, 0); 52 sw_write(&f, 0, 0);
52 » return r>=n ? -1 : r; 53 return r >= n ? -1 : r;
53 } 54 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698