bug-gnulib
[Top][All Lists]
Advanced

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

Re: Austin group ruling on ungetc vs. fflush


From: Bruno Haible
Subject: Re: Austin group ruling on ungetc vs. fflush
Date: Sat, 17 Jan 2009 14:45:26 +0100
User-agent: KMail/1.9.9

Hi Eric,

> In general, a big thanks for tackling this.  Have you filed a glibc bug
> report on this?

Done here: <http://sourceware.org/bugzilla/show_bug.cgi?id=9754>

> > -      off_t pos = lseek (fileno (fp), offset, whence);
> > +      /* We get here when an fflush() call immediately preceded this one.  
> > We
> > +    know there are no buffers.
> > +    POSIX requires us to modify the file descriptor's position.
> > +    But we cannot position beyond end of file here.  */
> > +      off_t pos =
> > +   lseek (fileno (fp),
> > +          whence == SEEK_END && offset > 0 ? 0 : offset,
> > +          whence);
> 
> I found this hunk a bit confusing in isolation; it should still be
> possible to seek beyond the end of a stream, with no impact until another
> action (such as fputc) modifies the stream, at which point NUL bytes are
> implicitly written in the gap between the former end of file and the new
> position.  Does this happen latter (if so, the comment could give a
> reference to that), or am I missing something by not reading the final
> resulting file?

This hunk is to be viewed in conjunction with the
   if (!(whence == SEEK_END && offset > 0))
a couple of lines below.

If you remove this special-casing, one of the tests in the testsuite fails.
Namely when the first fseek after fflush attempts to position beyond end of
file. That's something that lseek() does not support, but we are forced to
used lseek() in this situation, by POSIX. You can try to undo these two
hunks and fix the resulting test failure differently...

Bruno




reply via email to

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