bug-gnulib
[Top][All Lists]
Advanced

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

Re: portability of rewind


From: Bruno Haible
Subject: Re: portability of rewind
Date: Tue, 29 May 2007 00:49:55 +0200
User-agent: KMail/1.5.4

Eric Blake wrote:
> m4 had been using rewind to swap from appending to a
> temporary file representing a large diversion, to reading from offset 0 to
> copy that diversion to a different location.  But if the implicit fflush
> performed by the rewind fails, there is no way for the application to know
> about it, since rewind must also clear the error bit on the stream.  Which
> means that rewind can cause undetected data loss.

Apparently, yes.

> And which is why I'm
> checking in a patch to m4 today to avoid all use of rewind.
> ...
> Should we update stdio_.h to give a link warning that recommends avoiding
> all use of rewind?

This sounds exaggerated. You can recommend (for output streams and update
streams) to call  fflush (fp)  before  rewind (fp) , no?

OTOH, the code that avoids rewind is also not particularly complicated:

  if (fseeko (fp, 0, SEEK_SET) < 0) ...error-handling...
  clearerr (fp);

Bruno






reply via email to

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