summaryrefslogtreecommitdiff
path: root/src/stdio/fread.c
blob: b1b077dd23755193dc37c365fabfaf168a30771a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#if 0

#include <stdio.h>
#include "_stdio.h"

/** read directly from a file stream **/

size_t fread(void * restrict ptr, size_t size, size_t nmemb, FILE * restrict stream)
{
	unsigned char *buf = ptr;
	size_t n = 0;
	flockfile(stream);
	while (nmemb) {
		size_t i;
		for (i = 0; i < size; i++) {
			int c = fgetc(stream);
			if (c == EOF) {
				/* an error */
			} else {
				buf[i] = (char)c;
			}
		}
		nmemb--;
		buf += size;
		n++;
	}
	funlockfile(stream);
	/*
	RETURN_SUCCESS(the number of elements read);
	*/
	return n;
}

/***
reads up to ARGUMENT(nmemb) elements of ARGUMENT(size) bytes each
from ARGUMENT(stream) into the array at ARGUMENT(ptr).

The file position indicate is advanced by the number of bytes read.
***/

/*
STDC(1)
*/


#endif