What is the difference between read() and fread()?
read()
is a low level, unbuffered read. It makes a direct system call on UNIX.
fread()
is part of the C library, and provides buffered reads. It is usually implemented by calling read()
in order to fill its buffer.
Family read()
-> open
, close
, read
, write
Family fread()
-> fopen
, fclose
, fread
, fwrite
Family read:
- are system calls
- are not formatted IO: we have a non formatted byte stream
Family fread
- are functions of the standard C library (libc)
- use an internal buffer
- are formatted IO (with the "%.." parameter) for some of them
- use always the Linux buffer cache
More details here, although note that this post contains some incorrect information.