delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/11/06/08:43:47

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Sun, 6 Nov 2005 08:43:39 -0500
From: Christopher Faylor <cgf-no-personal-reply-please AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: BUG: alternatives
Message-ID: <20051106134339.GA24549@trixie.casa.cgf.cx>
Reply-To: cygwin AT cygwin DOT com
References: <436CF5E9 DOT 30106 AT cwilson DOT fastmail DOT fm> <001201c5e244$c9e50490$020aa8c0 AT DFW5RB41> <436D9993 DOT 7050100 AT cwilson DOT fastmail DOT fm>
Mime-Version: 1.0
In-Reply-To: <436D9993.7050100@cwilson.fastmail.fm>
User-Agent: Mutt/1.5.8i

On Sun, Nov 06, 2005 at 12:50:11AM -0500, Charles Wilson wrote:
>Gary R. Van Sickle wrote:
>>I'm not sure the test is actually valid anyway.  IIRC (and I may not, POSIX
>>may prove me wrong here), there's no guarantee that read() will return the
>>number of bytes you requested, so at a minium to make this 100% correct
>>you'd have to do something like this:
>>
>>// Read entire file
>>while(read(...) != 0)
>>{
>>}
>>
>>// Check if there was a read() failure or if it just ran out of bytes to
>>read.
>>[...]
>
>From my reading of 
>http://www.opengroup.org/onlinepubs/007908799/xsh/read.html it appears 
>that, while read doesn't always return the number of bytes requested, 
>when it DOES return something other than numbytesrequested in THIS 
>particular application we want to flag an error, and bail.
>
>e.g. a signal was received, there weren't enough bytes ready (timeout? 
>disk hardware error?), or we prematurely reached EOF...

A signal shouldn't cause a truncated read when retrieving data from
disk on cygwin or linux.

I think the only sane way to handle this is to put the read in a loop
and realloc the buffer as needed as long as the read continues to return
> 0.

It's obviously pretty racy to get the size of the file and then expect that
you'll be able to read in exactly that many bytes.

cgf

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019