Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 20331 invoked by uid 500); 18 Apr 2002 16:45:07 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 20320 invoked from network); 18 Apr 2002 16:45:06 -0000 Date: Thu, 18 Apr 2002 09:43:58 -0700 From: Jon Travis To: Cliff Woolley Cc: Stas Bekman , dev@apr.apache.org Subject: Re: apr file questions Message-ID: <20020418094358.A26205@covalent.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: ; from jwoolley@virginia.edu on Thu, Apr 18, 2002 at 10:40:12AM -0400 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N On Thu, Apr 18, 2002 at 10:40:12AM -0400, Cliff Woolley wrote: > On 18 Apr 2002, Jeff Trawick wrote: > > Since APR_EOF is one of the errors you might get back from > apr_file_read(), I agree with Jeff. This: > > > > while (apr_file_read(file, buffer, &len) != APR_SUCCESS) > > > { > > > ... > > > } > > is probably preferable. You'll most likely want to hang onto that return > code, though, like this: > > while ((rc = apr_file_read(file, buffer, &len)) != APR_SUCCESS) > { > ... > } Of course there is some amount of suckiness associated with this, because len will get mucked with by apr_file_read. I've seen this happen in more than one case where len gets reset so short reads occur. Ideally you always get the initial size back until the last couple times, but for files which grow as you are reading them, etc. this won't work out very well. So, you'd need: len = sizeof(buffer) while((rc = apr_file_read(file, buffer, &len)) != APR_SUCCESS){ ... len = sizeof(buffer) } I've been preferring to stick the buffer scoped locally to the loop, and have the read occur inside -- that way there is only one initialization of the length, and it's obvious: while(!apr_file_eof(file)){ char somebuf[1024]; apr_size_t len = sizeof(somebuf); if((rc = apr_file_read(file, somebuf, &len) .. blah blah blah } -- Jon