From: ceriel Date: Thu, 14 Jan 1993 10:02:28 +0000 (+0000) Subject: Fixed bug in flushbuf: did not reset stream->_ptr on write error X-Git-Tag: release-5-5~361 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=7eb7218667cb9e2bbc53c15ecd82028bb9c82bd7;p=ack.git Fixed bug in flushbuf: did not reset stream->_ptr on write error --- diff --git a/lang/cem/libcc.ansi/stdio/flushbuf.c b/lang/cem/libcc.ansi/stdio/flushbuf.c index d8bdc21cf..733fbb49e 100644 --- a/lang/cem/libcc.ansi/stdio/flushbuf.c +++ b/lang/cem/libcc.ansi/stdio/flushbuf.c @@ -83,7 +83,13 @@ __flushbuf(int c, FILE * stream) return c; } else if (io_testflag(stream, _IOLBF)) { *stream->_ptr++ = c; + /* stream->_count has been updated in putc macro. */ if (c == '\n' || stream->_count == -stream->_bufsiz) { + int count = -stream->_count; + + stream->_ptr = stream->_buf; + stream->_count = 0; + if (io_testflag(stream, _IOAPPEND)) { if (_lseek(fileno(stream), 0L, SEEK_END) == -1) { stream->_flags |= _IOERR; @@ -91,12 +97,9 @@ __flushbuf(int c, FILE * stream) } } if (! do_write(fileno(stream), (char *)stream->_buf, - -stream->_count)) { + count)) { stream->_flags |= _IOERR; return EOF; - } else { - stream->_ptr = stream->_buf; - stream->_count = 0; } } } else {