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

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

Powered by Google App Engine
This is Rietveld 408576698