Module: wine Branch: master Commit: 764b85511c72ab9e4b4ab456c98e0e71b4aa4009 URL: http://source.winehq.org/git/wine.git/?a=commit;h=764b85511c72ab9e4b4ab456c9...
Author: Piotr Caban piotr@codeweavers.com Date: Wed Nov 16 12:50:50 2011 +0100
msvcrt: Don't use fputc in flsbuf implementation.
---
dlls/msvcrt/file.c | 74 +++++++++++++++++++++++++++------------------------ 1 files changed, 39 insertions(+), 35 deletions(-)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 0ead68a..1334ec6 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -3062,37 +3062,6 @@ int CDECL MSVCRT__wfopen_s(MSVCRT_FILE** pFile, const MSVCRT_wchar_t *filename, return 0; }
-/* MSVCRT_fputc calls MSVCRT__flsbuf which calls MSVCRT_fputc */ -int CDECL MSVCRT__flsbuf(int c, MSVCRT_FILE* file); - -/********************************************************************* - * fputc (MSVCRT.@) - */ -int CDECL MSVCRT_fputc(int c, MSVCRT_FILE* file) -{ - int res; - - MSVCRT__lock_file(file); - if(file->_cnt>0) { - *file->_ptr++=c; - file->_cnt--; - if (c == '\n') - { - res = msvcrt_flush_buffer(file); - MSVCRT__unlock_file(file); - return res ? res : c; - } - else { - MSVCRT__unlock_file(file); - return c & 0xff; - } - } else { - res = MSVCRT__flsbuf(c, file); - MSVCRT__unlock_file(file); - return res; - } -} - /********************************************************************* * _flsbuf (MSVCRT.@) */ @@ -3109,10 +3078,17 @@ int CDECL MSVCRT__flsbuf(int c, MSVCRT_FILE* file) return MSVCRT_EOF; } if(file->_bufsiz) { - int res=msvcrt_flush_buffer(file); - if(!res) - res = MSVCRT_fputc(c, file); - return res; + int res = 0; + + if(file->_cnt == 0) + res = msvcrt_flush_buffer(file); + if(!res) { + *file->_ptr++ = c; + file->_cnt--; + res = msvcrt_flush_buffer(file); + } + + return res ? res : c&0xff; } else { unsigned char cc=c; int len; @@ -3127,6 +3103,34 @@ int CDECL MSVCRT__flsbuf(int c, MSVCRT_FILE* file) }
/********************************************************************* + * fputc (MSVCRT.@) + */ +int CDECL MSVCRT_fputc(int c, MSVCRT_FILE* file) +{ + int res; + + MSVCRT__lock_file(file); + if(file->_cnt>0) { + *file->_ptr++=c; + file->_cnt--; + if (c == '\n') + { + res = msvcrt_flush_buffer(file); + MSVCRT__unlock_file(file); + return res ? res : c; + } + else { + MSVCRT__unlock_file(file); + return c & 0xff; + } + } else { + res = MSVCRT__flsbuf(c, file); + MSVCRT__unlock_file(file); + return res; + } +} + +/********************************************************************* * _fputchar (MSVCRT.@) */ int CDECL MSVCRT__fputchar(int c)