1 #include "stdio_impl.h"
4 #define MIN(a,b) ((a)<(b) ? (a) : (b))
6 size_t fread(void *restrict destv
, size_t size
, size_t nmemb
, FILE *restrict f
)
8 unsigned char *dest
= destv
;
9 size_t len
= size
*nmemb
, l
= len
, k
;
16 if (f
->rpos
!= f
->rend
) {
17 /* First exhaust the buffer. */
18 k
= MIN(f
->rend
- f
->rpos
, l
);
19 memcpy(dest
, f
->rpos
, k
);
25 /* Read the remainder directly */
26 for (; l
; l
-=k
, dest
+=k
) {
27 k
= __toread(f
) ? 0 : f
->read(f
, dest
, l
);
38 weak_alias(fread
, fread_unlocked
);