Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.os.linux.misc Subject: Re: End of file mark Date: Wed, 19 Aug 2015 17:38:41 -0700 Organization: None to speak of Lines: 32 Message-ID: References: <87tws7qbx6.fsf@thumper.dhh.gt.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="4599"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/60nH/V0OfZ2mpAyAoIWmD" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:REZDODTFt5IrTmkFWXW+6uLUBSk= sha1:P4pxfhm36x0RVokWOpa2Wodrgx8= Xref: csiph.com comp.os.linux.misc:15171 Richard Kettlewell writes: > John Hasler 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 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"