Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #15171

Re: End of file mark

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.os.linux.misc
Subject Re: End of file mark
Date 2015-08-19 17:38 -0700
Organization None to speak of
Message-ID <lnvbca3ib2.fsf@kst-u.example.com> (permalink)
References <mqalh6$1fd$1@dont-email.me> <87tws7qbx6.fsf@thumper.dhh.gt.org> <wwvk2t3ouye.fsf@l1AntVDjLrnP7Td3DQJ8ynzIq3lJMueXf87AxnpFoA.invalid>

Show all headers | View raw


Richard Kettlewell <rjk@greenend.org.uk> writes:
> John Hasler <jhasler@newsguy.com> writes:
>> T writes:
>>> Under VFS and EXT4, do text files have an End Of File
>>> marker?
>>
>> No.
>>
>>> How do programs know when they are at the end of a file?
>>
>> The filesystem knows how long the file is.  It returns EOF ("end of
>> file").
>
> The EOF return value is synthesized by stdio.  The kernel just stops
> returning bytes when the end of the file is reached.

The read() system call takes an argument specifying how many bytes it
should attempt to read, and returns the number of bytes it was able to
read.  It returns 0 to indicate end-of-file.  (Returning a positive
count smaller than the size requested does not necessarily indicate
end-of-file.)  read() returns -1 on error.

The stdio input functions (on POSIX systems) are implemented on top of
read().  Each function (getchar(), fgets(), fread(), etc.) has its own
way to indicate an end-of-file condition.  Read the man page for each
input function to see how it does this.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.os.linux.misc | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

End of file mark T <T@invalid.invalid> - 2015-08-10 10:05 -0700
  Re: End of file mark John Hasler <jhasler@newsguy.com> - 2015-08-10 12:40 -0500
    Re: End of file mark Richard Kettlewell <rjk@greenend.org.uk> - 2015-08-10 19:32 +0100
      Re: End of file mark Keith Thompson <kst-u@mib.org> - 2015-08-19 17:38 -0700
  Re: End of file mark The Natural Philosopher <tnp@invalid.invalid> - 2015-08-10 19:52 +0100
    Re: End of file mark Pascal Hambourg <boite-a-spam@plouf.fr.eu.org> - 2015-08-11 12:40 +0200
      Re: End of file mark The Natural Philosopher <tnp@invalid.invalid> - 2015-08-11 11:51 +0100
  Re: End of file mark Robert Heller <heller@deepsoft.com> - 2015-08-10 16:05 -0500
    Re: End of file mark Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2015-08-10 21:16 +0000
      Re: End of file mark Tom Hardy <rhardy702@gmail.com> - 2015-08-11 23:34 -0500
        Re: End of file mark Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2015-08-12 14:57 +0000
          Re: End of file mark Tom Hardy <rhardy702@gmail.com> - 2015-08-13 11:28 -0500
  Re: End of file mark T <T@invalid.invalid> - 2015-08-11 10:27 -0700

csiph-web