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

Side by Side Diff: fusl/src/stdio/vswprintf.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « fusl/src/stdio/vsscanf.c ('k') | fusl/src/stdio/vswscanf.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include "stdio_impl.h"
2 #include <limits.h>
3 #include <string.h>
4 #include <errno.h>
5 #include <stdint.h>
6 #include <wchar.h>
7
8 struct cookie {
9 wchar_t *ws;
10 size_t l;
11 };
12
13 static size_t sw_write(FILE *f, const unsigned char *s, size_t l)
14 {
15 size_t l0 = l;
16 int i = 0;
17 struct cookie *c = f->cookie;
18 if (s!=f->wbase && sw_write(f, f->wbase, f->wpos-f->wbase)==-1)
19 return -1;
20 while (c->l && l && (i=mbtowc(c->ws, (void *)s, l))>=0) {
21 s+=i;
22 l-=i;
23 c->l--;
24 c->ws++;
25 }
26 *c->ws = 0;
27 return i<0 ? i : l0;
28 }
29
30 int vswprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, va_lis t ap)
31 {
32 int r;
33 FILE f;
34 unsigned char buf[256];
35 struct cookie c = { s, n-1 };
36
37 memset(&f, 0, sizeof(FILE));
38 f.lbf = EOF;
39 f.write = sw_write;
40 f.buf_size = sizeof buf;
41 f.buf = buf;
42 f.lock = -1;
43 f.cookie = &c;
44 if (!n) {
45 return -1;
46 } else if (n > INT_MAX) {
47 errno = EOVERFLOW;
48 return -1;
49 }
50 r = vfwprintf(&f, fmt, ap);
51 sw_write(&f, 0, 0);
52 return r>=n ? -1 : r;
53 }
OLDNEW
« no previous file with comments | « fusl/src/stdio/vsscanf.c ('k') | fusl/src/stdio/vswscanf.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698