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

Side by Side Diff: fusl/src/stdio/fread.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/regex/regcomp.c ('k') | fusl/src/stdio/fwrite.c » ('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 #define MIN(a,b) ((a)<(b) ? (a) : (b)) 4 #define MIN(a,b) ((a)<(b) ? (a) : (b))
5 5
6 size_t fread(void *restrict destv, size_t size, size_t nmemb, FILE *restrict f) 6 size_t fread(void *restrict destv, size_t size, size_t nmemb, FILE *restrict f)
7 { 7 {
8 unsigned char *dest = destv; 8 unsigned char *dest = destv;
9 size_t len = size*nmemb, l = len, k; 9 size_t len = size*nmemb, l = len, k;
10 if (!size) nmemb = 0;
10 11
11 FLOCK(f); 12 FLOCK(f);
12 13
13 f->mode |= f->mode-1; 14 f->mode |= f->mode-1;
14 15
15 if (f->rend - f->rpos > 0) { 16 if (f->rend - f->rpos > 0) {
16 /* First exhaust the buffer. */ 17 /* First exhaust the buffer. */
17 k = MIN(f->rend - f->rpos, l); 18 k = MIN(f->rend - f->rpos, l);
18 memcpy(dest, f->rpos, k); 19 memcpy(dest, f->rpos, k);
19 f->rpos += k; 20 f->rpos += k;
20 dest += k; 21 dest += k;
21 l -= k; 22 l -= k;
22 } 23 }
23 24
24 /* Read the remainder directly */ 25 /* Read the remainder directly */
25 for (; l; l-=k, dest+=k) { 26 for (; l; l-=k, dest+=k) {
26 k = __toread(f) ? 0 : f->read(f, dest, l); 27 k = __toread(f) ? 0 : f->read(f, dest, l);
27 if (k+1<=1) { 28 if (k+1<=1) {
28 FUNLOCK(f); 29 FUNLOCK(f);
29 return (len-l)/size; 30 return (len-l)/size;
30 } 31 }
31 } 32 }
32 33
33 FUNLOCK(f); 34 FUNLOCK(f);
34 return nmemb; 35 return nmemb;
35 } 36 }
36 37
37 weak_alias(fread, fread_unlocked); 38 weak_alias(fread, fread_unlocked);
OLDNEW
« no previous file with comments | « fusl/src/regex/regcomp.c ('k') | fusl/src/stdio/fwrite.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698