Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 81966 invoked by uid 500); 18 Apr 2002 14:38:28 -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 81953 invoked from network); 18 Apr 2002 14:38:28 -0000 Message-ID: <3CBEDA5F.6030200@stason.org> Date: Thu, 18 Apr 2002 22:38:23 +0800 From: Stas Bekman Organization: Hope, Humanized User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9) Gecko/00200203 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jeff Trawick Cc: dev@apr.apache.org Subject: Re: apr file questions References: <3CBD39FA.7040505@stason.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Jeff Trawick wrote: > Stas Bekman writes: > > >>2. What's the idiomatic apr read till eof? From grepping the source >>code, I see apr_file_eof is hardly ever used. Is something wrong with: >> >> while (!apr_file_eof(fp)) { >> rc = apr_file_read(fp, buf, &nbytes); >> ... >> } >> >>I saw code like this: >> >> while (apr_file_read(file, buffer, &len) != APR_SUCCESS) >> { >> ... >> } >> >>which one is better to use? > > > I would suggest the second one. What if you hit an I/O error? That's what rc = apr_file_read() is for, the following line with ... is for error checking. > I > always did > > while (!feof() && !ferror()) > > with stdio. If you use a second or your example and have an IO error, this code won't be able to tell eof from an error, and simply move on. Is this good? Thanks Jeff __________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:stas@stason.org http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com