Search code examples
cglibcstdiofgetsfgetc

How does fgetc work internally


Does it actually read character by character or does it read some bytes into the kernel buffer and return to the user- character by character?

Is it the same with fgets?

Let me say I use glibc and a gcc compiler.


Solution

  • Almost right. A typical modern implementation that does have a user/kernel separation stores the bytes in a user buffer, not in a kernel buffer. Thus many calls to fgetc actually trigger few true system calls.