[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: strfile: new module

From: Paul Eggert
Subject: Re: strfile: new module
Date: Wed, 31 May 2006 12:15:15 -0700
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

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

[Prev in Thread] Current Thread [Next in Thread]