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

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

Powered by Google App Engine
This is Rietveld 408576698