Module: wine Branch: master Commit: 5bf1ae82f19b915e75f12e748ad6a8fd3185001e URL: http://source.winehq.org/git/wine.git/?a=commit;h=5bf1ae82f19b915e75f12e748a...
Author: Dan Kegel dank@kegel.com Date: Wed Jan 28 21:42:01 2009 -0800
msvcrt: _flsbuf zeroes _cnt.
---
dlls/msvcrt/file.c | 2 ++ dlls/msvcrt/tests/file.c | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletions(-)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index ed23d02..2740cfa 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -2592,6 +2592,8 @@ int CDECL MSVCRT__flsbuf(int c, MSVCRT_FILE* file) } else { unsigned char cc=c; int len; + /* set _cnt to 0 for unbuffered FILEs */ + file->_cnt = 0; len = MSVCRT__write(file->_file, &cc, 1); if (len == 1) return c & 0xff; file->_flag |= MSVCRT__IOERR; diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index b783b51..3c8844b 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -471,9 +471,10 @@ static void test_flsbuf( void ) { char* tempf; FILE *tempfh; + int c; int ret; int bufmode; - int bufmodes[] = {_IOFBF,_IONBF}; + static const int bufmodes[] = {_IOFBF,_IONBF};
tempf=_tempnam(".","wne"); for (bufmode=0; bufmode < sizeof(bufmodes)/sizeof(bufmodes[0]); bufmode++) @@ -497,6 +498,26 @@ static void test_flsbuf( void ) ok(EOF == ret, "_flsbuf(0,tempfh) on r/o file expected %x got %x\n", EOF, ret); fclose(tempfh);
+ /* See bug 17123, exposed by WinAVR's make */ + tempfh = fopen(tempf,"w"); + ok(tempfh->_cnt == 0, "_cnt on freshly opened file was %d\n", tempfh->_cnt); + setbuf(tempfh, NULL); + ok(tempfh->_cnt == 0, "_cnt on unbuffered file was %d\n", tempfh->_cnt); + /* Inlined putchar sets _cnt to -1. Native seems to ignore the value... */ + tempfh->_cnt = 1234; + ret = _flsbuf('Q',tempfh); + ok('Q' == ret, "_flsbuf('Q',tempfh) expected %x got %x\n", 'Q', ret); + /* ... and reset it to zero */ + ok(tempfh->_cnt == 0, "after unbuf _flsbuf, _cnt was %d\n", tempfh->_cnt); + fclose(tempfh); + /* And just for grins, make sure the file is correct */ + tempfh = fopen(tempf,"r"); + c = fgetc(tempfh); + ok(c == 'Q', "first byte should be 'Q'\n"); + c = fgetc(tempfh); + ok(c == EOF, "there should only be one byte\n"); + fclose(tempfh); + unlink(tempf); }