bug-gnulib
[Top][All Lists]
Advanced

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

Re: fflush after ungetc


From: Bruno Haible
Subject: Re: fflush after ungetc
Date: Sun, 9 Mar 2008 21:45:06 +0100
User-agent: KMail/1.5.4

Eric Blake wrote:
> But my questions about fflush on seekable input streams after ungetc still
> remain.

There are also two cases to consider:
  1) ungetc of the last byte read,
  2) ungetc of a different byte value.

Three results are possible:
  a. set the file descriptor's position to the stream's current file-position
     indicator, discard the read-ahead buffer, and discard the ungetc buffer.
  b. set the file descriptor's position to the stream's file-position indicator
     in effect before the bytes were pushed back, discard the read-ahead buffer,
     and discard the ungetc buffer.
  c. set the file descriptor's position to the stream's file-position indicator
     in effect before the bytes were pushed back, discard the read-ahead buffer,
     but keep the ungetc buffer.

If one wants the file descriptor to reflect most faithfully what happens in the
stream, the combinations 1a+2b or 1a+2c are the best.

If one wants fflush() to be an "optional" operation, i.e. which does not
change the bytes returned by subsequent fgetc() calls, then 1b, 2a, 2b must
not occur, i.e. the only possible combinations are 1a+2c and 1c+2c.

If one does not want ungetc to distinguish the two cases 1 and 2, the only
possible combinations are 1a+2a, 1b+2b, 1c+2c.

Bruno





reply via email to

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