• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: eof() for file descriptors missing?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: eof() for file descriptors missing?


  • Subject: Re: eof() for file descriptors missing?
  • From: Scott Andrew <email@hidden>
  • Date: Wed, 30 Jan 2008 11:49:07 -0800

Thanks. That makes prefect sense..

Scott

On Jan 30, 2008, at 9:41 AM, Alastair Houghton wrote:

On 30 Jan 2008, at 07:26, Chris Espinosa wrote:

If you're using NSFileHandle readDataOfLength:, you're at EOF if the size of the data is 0 or less than the length desired.

If you're using read(), you're at EOF when read returns 0.

If you're using fread, you're at EOF when fread returns a size_ that's 0 or smaller than nitems, or feof() returns true.

That's not quite the whole story.

If you're using fread(), you're at EOF when fread() returns 0, *and* feof() returns true. It can return 0 with feof() false, for instance if there is a read error in the middle of a file, in which case ferror() will be true instead; in that case, you haven't finished reading the file. I suspect a lot of programs (probably including a number of mine) think that they've finished reading in that case, though they certainly shouldn't.

Additionally, both fread() and NSFileHandle can return less than the amount requested if the underlying fd is a communications channel rather than a file, even if there will be more data to follow. The likelihood of that situation may vary from application to application, but it might be better to explicitly check for *zero* bytes returned, rather than less-than-expected, since the extra read is (AFAIK) harmless.

Kind regards,

Alastair.

--
http://alastairs-place.net




_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >eof() for file descriptors missing? (From: Scott Andrew <email@hidden>)
 >Re: eof() for file descriptors missing? (From: Chris Espinosa <email@hidden>)
 >Re: eof() for file descriptors missing? (From: Alastair Houghton <email@hidden>)

  • Prev by Date: Xc3 Distributed Builds: What's the difference between Dedicated and Workgroup?
  • Next by Date: Changing a nib bundle's format
  • Previous by thread: Re: eof() for file descriptors missing?
  • Next by thread: C++ static locals share a global mutex? - deadlock issue
  • Index(es):
    • Date
    • Thread