Thread (151 messages) 151 messages, 6 authors, 2017-05-11

Re: [PATCH 10/26] Check for EOF while parsing mails

From: Johannes Schindelin <hidden>
Date: 2017-04-28 13:37:20

Hi Peff,

On Fri, 28 Apr 2017, Jeff King wrote:
On Fri, Apr 28, 2017 at 12:44:52PM +0200, Johannes Schindelin wrote:
quoted
quoted
Also, what is the behavior of ungetc when we pass it EOF?
According to the documentation, it would cast EOF to an unsigned char and
push that back. Definitely incorrect.
quoted
It looks like POSIX does what we want (pushing EOF is a noop, and the
stream retains its feof() status), but I don't know if there are other
implementations to worry about.
That's not what my man page here says:

	ungetc()  pushes  c  back to stream, cast to unsigned char, where
	it is available for subsequent read operations.  Pushed-back
	characters will be returned in reverse order; only one pushback is
	guaranteed.
POSIX covers this this case explicitly:

  If the value of c equals that of the macro EOF, the operation shall
  fail and the input stream shall be left unchanged.

That comes straight from C99, which says:

  If the value of c equals that of the macro EOF, the operation fails
  and the input stream is unchanged.

I don't have a copy of C89 handy, but I didn't see any mention of the
behavior in the "changes from the previous edition" section of C99.
Yeah. I'd still be more comfortable with being explicit in this case, also
because our documentation states explicitly that we do not necessarily
live by the POSIX standard.

Ciao,
Dscho
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help