I was looking at the source code of fread in chromium-os / glibc and became increasingly puzzled about it.
NB: I am talking about the source code and NOT the use of fread or other related questions
Function prototype as a macro
First I was surprised about the way that fread is declared as a macro with its function name, followed by its arguments and finally its arguments' type:
/* Read NMEMB chunks of SIZE bytes each from STREAM into P. */
size_t
DEFUN(fread, (p, size, nmemb, stream),
PTR p AND size_t size AND size_t nmemb AND register FILE *stream)
What is the rationale behind this and why not
size_t fread(PTR p, size_t size, size_t nmemb, register FILE * stream)
which is much more readable?
What is __fillbf(register FILE *stream)
I was especially puzzled about this line:
int c = __fillbf(stream);
and could not find this function anywhere. I thought that it could be a system call that I don't already know about but it is not part of the table
So what is the real code behind __fill_bf(register FILE *)
?
Edit: Thanks to dyp for macro definition, Crowman for __fillbf
and Ray for the nice synthesis of explanation!
ps: any answer with some extra explanations about the tricky parts of fread are also welcome!