Mail Archives: djgpp/1997/07/21/12:46:22
On Wed, 16 Jul 1997, A. Sinan Unur wrote:
> A. Sinan Unur wrote:
>
> off calling the function as
>
> fread(buf, 1, size*n, stream)
>
> instead of
>
> fread(buf, size, n, stream)."
>
> it follows that you can only count on fread returning zero in case of
> failure if you use the latter form.
No. You can only depend on fread returning zero on error if you call it as:
fread(buf,size,n=1,stream);
If n > 1 fread may detect an error during processing of the n'th record
or the n-1'st record in which case fread returns the number of records
correctly and completely read. I agree with P.J. Plauger about partial
records with the proviso that iff you can extract useful information from
a partial record or somehow recover the unread portion reading a single
byte at a time may give you more control. (Ex: stream is a socket and
records are long enough to be broken into multiple IP packets and the
connection is slow enough to timeout such that sleeping and rereading the
stream may get the missing part of the record.) Otherwise, who cares
about partial records in the general case? Usually if I do not get an
entire record I need to just declare an error and recover.
Art S. Kagel, kagel AT bloomberg DOT com
- Raw text -