Looks nice.  A couple of comments:

> +      count = fread (buf + size, 1, BUFSIZ, stream);

BUFSIZ is too small on many systems, for backward compatibility reasons.
Why not change that "BUFSIZ" to "alloc - size - 1"?

Also, for the common case of regular files that you have opened,
you can use fstat to cheaply find out an estimated size for the file,
and use that estimate rather than guessing and growing the buffer.
The estimate might be wrong (due to binary file translation, or
growing sizes), but still, it's better than a guess.

Even if it is a regular file that you have not opened, you can still
estimate the size of the remaining part of the file by subtracting
lseek (..., SEEK_CUR) from fstat.

> +           if (buf)
> +             free (buf);

How about just 'free (buf);'; that's smaller.


Reply via email to