read vs fread

From: Patrice Kadionik (kadionik_at_enseirb.fr)
Date: 02/24/05


Date: Thu, 24 Feb 2005 21:46:11 +0100

Hi all,

I want to make a brief comparison between read() and fread() (under a
Linux OS).

1. Family read and Co: open, close, read, write, ioctl...
2. Family fread and Co: fopen, fclose, fread, fwrite, fcntl...

Family read and Co:
- are not C standard.
- are syscalls.
- are not formatted IO : we have a non formatted byte stream.
- don't use the Linux buffer cache.
- generally used for accessing character devices. fread and Co is possible.

Family fread and Co:
- are C standard.
- are functions of the standard IO libc (glibc).
- use an internal buffer (in their coding)
- are formatted IO (with the "%.." parameter) for some of them.
- use always the Linux buffer cache.
- generally used for accessing bloc devices.

When I'm opening an ordinary file on a HD (bloc device), I'm always
using the buffer cache with open or fopen. In case of fopen, I'm using
in addition an internal buffer when I'm doing a fread or fwrite for
speeding HD access.
When I'm opening an character device, I'm not using the buffer cache.
Open and Co are generally used here but fopen and Co is possible too.

Is is OK?
Some points I've forgotten?

Thank you for your response;
Pat.



Relevant Pages

  • read vs fread
    ... Family fread and Co: ... generally used for accessing character devices. ... use always the Linux buffer cache. ...
    (comp.lang.c)
  • read vs fread
    ... Family fread and Co: ... generally used for accessing character devices. ... use always the Linux buffer cache. ...
    (comp.unix.programmer)
  • Re: read vs fread
    ... so readis the low level function that the standard C funtions use ... What do you mean by "Linux buffer cache"? ... fwriteand fread() also don't. ...
    (comp.os.linux.development.system)
  • Re: read vs fread
    ... > Family fread and Co: ... > - use always the Linux buffer cache. ... > When I'm opening an character device, I'm not using the buffer cache. ...
    (comp.lang.c)