Author: akhaldi Date: Mon May 12 15:32:43 2014 New Revision: 63257
URL: http://svn.reactos.org/svn/reactos?rev=63257&view=rev Log: [CRT] * Update fwrite(). CORE-8080
Modified: trunk/reactos/lib/sdk/crt/stdio/file.c
Modified: trunk/reactos/lib/sdk/crt/stdio/file.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/stdio/file.c?re... ============================================================================== --- trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] Mon May 12 15:32:43 2014 @@ -2506,33 +2506,36 @@ return 0;
_lock_file(file); - if(file->_cnt) { - int pcnt=((unsigned)file->_cnt>wrcnt)? wrcnt: file->_cnt; - memcpy(file->_ptr, ptr, pcnt); - file->_cnt -= pcnt; - file->_ptr += pcnt; - written = pcnt; - wrcnt -= pcnt; - ptr = (const char*)ptr + pcnt; - } else if(!(file->_flag & _IOWRT)) { - if(file->_flag & _IORW) { - file->_flag |= _IOWRT; + + while(wrcnt) { + if(file->_cnt) { + int pcnt=((unsigned)file->_cnt>wrcnt)? wrcnt: file->_cnt; + memcpy(file->_ptr, ptr, pcnt); + file->_cnt -= pcnt; + file->_ptr += pcnt; + written += pcnt; + wrcnt -= pcnt; + ptr = (const char*)ptr + pcnt; + } else if(!file->_bufsiz && (file->_flag & _IONBF)) { + if(!(file->_flag & _IOWRT)) { + if(file->_flag & _IORW) + file->_flag |= _IOWRT; + else + break; + } + + if(_write(file->_file, ptr, wrcnt) <= 0) { + file->_flag |= _IOERR; + break; + } + written += wrcnt; + wrcnt = 0; } else { - _unlock_file(file); - return 0; - } - } - if(wrcnt) { - /* Flush buffer */ - int res=flush_buffer(file); - if(!res) { - int pwritten = _write(file->_file, ptr, wrcnt); - if (pwritten <= 0) - { - file->_flag |= _IOERR; - pwritten=0; - } - written += pwritten; + if(_flsbuf(*(const char*)ptr, file) == EOF) + break; + written++; + wrcnt--; + ptr = (const char*)ptr + 1; } }