[Top][All Lists]

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

Re: strfile: new module

From: Simon Josefsson
Subject: Re: strfile: new module
Date: Wed, 31 May 2006 14:15:59 +0200
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (gnu/linux)

Bruno Haible <address@hidden> writes:

>> Index: modules/strfile
> I would call the module 'read-file' and the function 'read_file'. So that it's
> possible to add a module 'write_file' if needed, and for consistency with the
> 'copy-file' module.

I like this, and I also like your fread_file function.  I will create
a module read-file with two functions fread_file and read_file.

>> +  do {
> In GNU style the brace goes on the next line.

I'll indent it.

Hmmm.  I've made the same mistake before.  I'll see how hard it would
be to write a tool that will "prepare" additions of a gnulib module,
for one it should run indent on the files, and then run 'cvs
--new-file diff' on the modules file, and the files mentioned in the
modules file.  Eventually, it could apply the tests from the
maintainer-makefile module.

>> +    tmp = realloc (out, pos + BUFSIZ);
> Quadratic runtime behaviour: if you don't have particular luck with the 
> realloc()
> implementation, for large files, this loop will spend most of its time in
> realloc(), copying memory around.

Your fread_file may solve this, and read_file will use it.

>> +  if (!(feof (fh) && fclose (fh)))
> Missing treatment of the ferror (fh) case.

Same here.

> As additional input, find attached some similar (unpolished) code I wrote 
> long ago
> in the past. The good point about a function that takes a FILE stream rather
> than a filename as argument is that the caller has more liberty to decide
> about O_TEXT / O_BINARY and about what to do when the file does not exist.


> The downside is, of course, that it's not so immediate to use this
> function. But maybe the module can provide both: fread_file that
> reads from a stream, and read_file that takes a filename?



reply via email to

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