file reader functions - Unix

This is a discussion on file reader functions - Unix ; Hello all. I need some help with this one: Basically, I know that file reader functions need to be able to report when the end of the file reached. Why not just dedicate a special character, such as control-Z (26 ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: file reader functions

  1. file reader functions

    Hello all. I need some help with this one:
    Basically, I know that file reader functions need to be able to report
    when the end of the file reached. Why not just dedicate a special
    character, such as control-Z (26 dec) to this task?
    This is a question that I have wanted to know for some time. Please
    give me some knowledge...

    newbie...


  2. Re: file reader functions

    uraniumore235@hotmail.com wrote:
    > Hello all. I need some help with this one:
    > Basically, I know that file reader functions need to be able to report
    > when the end of the file reached. Why not just dedicate a special
    > character, such as control-Z (26 dec) to this task?
    > This is a question that I have wanted to know for some time. Please
    > give me some knowledge...


    Because then you can't have that character somewhere within the
    file. That might be acceptable for text files where that character
    probably will be rather unlikely to appear, but in binary files
    (programs, images etc.) this value is rather like to show up, so
    it can't be used to encode some special meaning like EOF. And
    there's no character that can't show up in binary files, so
    there's no character that could be used for EOF.

    Regards, Jens
    --
    \ Jens Thoms Toerring ___ jt@toerring.de
    \__________________________ http://toerring.de

  3. Re: file reader functions

    On Feb 7, 10:01 pm, uraniumore...@hotmail.com wrote:
    > Hello all. I need some help with this one:
    > Basically, I know that file reader functions need to be able to report
    > when the end of the file reached. Why not just dedicate a special
    > character, such as control-Z (26 dec) to this task?


    Why?

    First off, Unix records the exact length of the file, outside of the
    contents of the file. There's no need to include a special character
    within the file contents to mark the end of the file, when the end of
    the file is already plainly marked (by the physical end of the file).

    Secondly, as Jens points out, placing a special character in the file
    might work for "text"-like files, but won't work for data (arbitrary
    binary contents) files. /And/ Unix makes no special distinction
    between "text" files and "data" files; that distinction is up to each
    application to make. So, to use a special character would require
    severe restrictions on the kernel (support for text files only /
    special handling of the contents of binary files to detect EOF), and/
    or on each application.

    In other words, using a data stream character to mark End-of-file is a
    dumb idea that isn't necessary in Unix.

    > This is a question that I have wanted to know for some time. Please
    > give me some knowledge...
    >
    > newbie...


    HTH
    --
    Lew


+ Reply to Thread