From 29a7aa12882d85b2c9f6ce194a15ef5fdf85b787 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Wed, 1 Jun 2011 12:08:02 +0000 Subject: [PATCH] [CRT] in _flsbuf, always reset _cnt to 0 and don't allocate/use a buffer when _IONBUF is set. Fixes a regression in msvcrt_winetest file. See issue #5829 for more details. svn path=/trunk/; revision=52040 --- reactos/lib/sdk/crt/stdio/_flsbuf.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/reactos/lib/sdk/crt/stdio/_flsbuf.c b/reactos/lib/sdk/crt/stdio/_flsbuf.c index c2b7df29d4c..8eeeba1125a 100644 --- a/reactos/lib/sdk/crt/stdio/_flsbuf.c +++ b/reactos/lib/sdk/crt/stdio/_flsbuf.c @@ -24,6 +24,9 @@ _flsbuf(int ch, FILE *stream) return EOF; } + /* Always reset _cnt */ + stream->_cnt = 0; + /* Check if this was a read buffer */ if (stream->_flag & _IOREAD) { @@ -31,7 +34,6 @@ _flsbuf(int ch, FILE *stream) if (!(stream->_flag & _IOEOF)) { stream->_flag |= _IOERR; - stream->_cnt = 0; return EOF; } @@ -43,16 +45,17 @@ _flsbuf(int ch, FILE *stream) stream->_flag &= ~(_IOREAD|_IOEOF); stream->_flag |= _IOWRT; - /* If we have no buffer, try to allocate one */ - if (!stream->_base && stream != stdout && stream != stderr) + /* Check if should get a buffer */ + if (!(stream->_flag & _IONBF) && stream != stdout && stream != stderr) { - alloc_buffer(stream); + /* If we have no buffer, try to allocate one */ + if (!stream->_base) alloc_buffer(stream); } - /* Check if we have a buffer now */ - if (stream->_base) + /* Check if we can use a buffer now */ + if (stream->_base && !(stream->_flag & _IONBF)) { - /* We have one, check if there is something to write */ + /* We can, check if there is something to write */ count = stream->_ptr - stream->_base; if (count > 0) written = _write(stream->_file, stream->_base, count);