read vs fread

Discussion in 'C Programming' started by Patrice Kadionik, Feb 24, 2005.

  1. 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, swrite, fcntl...


    Family read and Co:
    - 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.


    Family fread and Co:
    - 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.

    Is is OK?
    Some points I've forgotten?

    Thank you for your response;
    Pat.
     
    Patrice Kadionik, Feb 24, 2005
    #1
    1. Advertising

  2. Patrice Kadionik

    Ben Pfaff Guest

    Patrice Kadionik <> writes:

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


    This is not the place to do it. Try a Linux programming
    newsgroup.
    --
    Ben Pfaff
    email:
    web: http://benpfaff.org
     
    Ben Pfaff, Feb 24, 2005
    #2
    1. Advertising

  3. Patrice Kadionik

    jacob navia Guest

    Patrice Kadionik wrote:

    > 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, swrite, fcntl...
    >
    >
    > Family read and Co:
    > - 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.
    >
    >
    > Family fread and Co:
    > - 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.
    >
    > Is is OK?
    > Some points I've forgotten?
    >
    > Thank you for your response;
    > Pat.



    I think that's quite OK. Maybe a small point, you can read
    from a character device using fread, or fgetc, for instance
    you can read from the keyboard...
     
    jacob navia, Feb 24, 2005
    #3
  4. Hi Jacob,
    You're right!
    You may use fread on a character device (a serial line for example).
    Interesting when the byte stream is ASCII character oriented...
    Thanks;
    Pat.

    jacob navia wrote:
    > Patrice Kadionik wrote:
    >
    >> 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, swrite, fcntl...
    >>
    >>
    >> Family read and Co:
    >> - 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.
    >>
    >>
    >> Family fread and Co:
    >> - 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.
    >>
    >> Is is OK?
    >> Some points I've forgotten?
    >>
    >> Thank you for your response;
    >> Pat.

    >
    >
    >
    > I think that's quite OK. Maybe a small point, you can read
    > from a character device using fread, or fgetc, for instance
    > you can read from the keyboard...
    >
     
    Patrice Kadionik, Feb 24, 2005
    #4
  5. Patrice Kadionik

    Eric Sosman Guest

    Patrice Kadionik wrote:
    > Hi all,
    >
    > I want to make a brief comparison between read() and fread() (under a
    > Linux OS).


    Only a few of your questions are about the C language,
    so I will give very brief answers. For more information,
    please try a Linux or Unix newsgroup.

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


    I think "swrite" should be "fwrite." Also, "fcntl" does
    not belong in this list.

    > Family read and Co:
    > - are syscalls.
    > - are not formatted IO : we have a non formatted byte stream.
    > - don't use the Linux buffer cache.


    They probably *do* use the buffer cache when reading
    and writing disk files.

    > - generally used for accessing character devices.


    No; they can be used with any devices.

    > Family fread and Co:
    > - are functions of the standard IO libc (glibc).


    They are library functions specified by the C language
    Standard.

    > - use an internal buffer (in their coding)


    Usually, but not necessarily.

    > - are formatted IO (with the "%.." parameter) for some of them.
    > - use always the Linux buffer cache.


    The probably do *not* use the buffer cache when reading
    and writing things that are not disk files.

    > - generally used for accessing bloc devices.


    No; they can be used with any devices the implementation
    supports.

    > 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.


    Usually, but not necessarily.

    > When I'm opening an character device, I'm not using the buffer cache.
    > Open and Co are generally used here.


    You are probably not using the buffer cache, but there
    is no problem using fopen() with these devices -- think about
    using getchar() to read keyboard input, for example.

    > Is is OK?
    > Some points I've forgotten?


    comp.unix.programmer, or Linux newsgroups.

    --
     
    Eric Sosman, Feb 24, 2005
    #5
  6. Patrice Kadionik <> writes:
    > I want to make a brief comparison between read() and fread() (under a
    > Linux OS).


    fread() is defined by the C standard; read() is not. For more
    details, try a Linux-specific newsgroup, or perhaps
    comp.unix.programmer.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Feb 24, 2005
    #6
  7. OK,
    sorry...
    Pat.
    Keith Thompson wrote:
    > Patrice Kadionik <> writes:
    >
    >>I want to make a brief comparison between read() and fread() (under a
    >>Linux OS).

    >
    >
    > fread() is defined by the C standard; read() is not. For more
    > details, try a Linux-specific newsgroup, or perhaps
    > comp.unix.programmer.
    >
     
    Patrice Kadionik, Feb 24, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.amnet.net.au

    Equivalent of "fread" C function in Java

    news.amnet.net.au, Jan 15, 2004, in forum: Java
    Replies:
    2
    Views:
    4,886
  2. Patrick
    Replies:
    6
    Views:
    921
    Roedy Green
    Jul 13, 2004
  3. Axel
    Replies:
    12
    Views:
    677
  4. Meenakshi Matai

    fread can not read particular data

    Meenakshi Matai, Jun 24, 2004, in forum: C Programming
    Replies:
    4
    Views:
    424
    Meenakshi Matai
    Jun 24, 2004
  5. Sheth Raxit
    Replies:
    1
    Views:
    505
    Richard Heathfield
    Nov 23, 2007
Loading...

Share This Page