apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <traw...@attglobal.net>
Subject Re: apr file questions
Date Thu, 18 Apr 2002 14:51:11 GMT
Stas Bekman <stas@stason.org> writes:

> 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?

obviously you would save the apr_status_t :)

-- 
Jeff Trawick | trawick@attglobal.net
Born in Roswell... married an alien...

Mime
View raw message