apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject Re: apr file questions
Date Thu, 18 Apr 2002 14:38:23 GMT
Jeff Trawick wrote:
> Stas Bekman <stas@stason.org> 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


Mime
View raw message