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

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

Issue 1689833004: [fusl] Update fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: remove stray space 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
« no previous file with comments | « fusl/src/stdio/fread.c ('k') | fusl/src/thread/arm/atomics.s » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "stdio_impl.h" 1 #include "stdio_impl.h"
2 #include <string.h> 2 #include <string.h>
3 3
4 size_t __fwritex(const unsigned char *restrict s, size_t l, FILE *restrict f) 4 size_t __fwritex(const unsigned char *restrict s, size_t l, FILE *restrict f)
5 { 5 {
6 size_t i=0; 6 size_t i=0;
7 7
8 if (!f->wend && __towrite(f)) return 0; 8 if (!f->wend && __towrite(f)) return 0;
9 9
10 if (l > f->wend - f->wpos) return f->write(f, s, l); 10 if (l > f->wend - f->wpos) return f->write(f, s, l);
11 11
12 if (f->lbf >= 0) { 12 if (f->lbf >= 0) {
13 /* Match /^(.*\n|)/ */ 13 /* Match /^(.*\n|)/ */
14 for (i=l; i && s[i-1] != '\n'; i--); 14 for (i=l; i && s[i-1] != '\n'; i--);
15 if (i) { 15 if (i) {
16 » » » if (f->write(f, s, i) < i) 16 » » » size_t n = f->write(f, s, i);
17 » » » » return i; 17 » » » if (n < i) return n;
18 s += i; 18 s += i;
19 l -= i; 19 l -= i;
20 } 20 }
21 } 21 }
22 22
23 memcpy(f->wpos, s, l); 23 memcpy(f->wpos, s, l);
24 f->wpos += l; 24 f->wpos += l;
25 return l+i; 25 return l+i;
26 } 26 }
27 27
28 size_t fwrite(const void *restrict src, size_t size, size_t nmemb, FILE *restric t f) 28 size_t fwrite(const void *restrict src, size_t size, size_t nmemb, FILE *restric t f)
29 { 29 {
30 size_t k, l = size*nmemb; 30 size_t k, l = size*nmemb;
31 if (!size) nmemb = 0;
31 FLOCK(f); 32 FLOCK(f);
32 k = __fwritex(src, l, f); 33 k = __fwritex(src, l, f);
33 FUNLOCK(f); 34 FUNLOCK(f);
34 return k==l ? nmemb : k/size; 35 return k==l ? nmemb : k/size;
35 } 36 }
36 37
37 weak_alias(fwrite, fwrite_unlocked); 38 weak_alias(fwrite, fwrite_unlocked);
OLDNEW
« no previous file with comments | « fusl/src/stdio/fread.c ('k') | fusl/src/thread/arm/atomics.s » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698