mirror of
https://github.com/reactos/reactos.git
synced 2024-07-06 12:45:16 +00:00
[CRT]
* Update fwrite(). CORE-8080 svn path=/trunk/; revision=63257
This commit is contained in:
parent
c36bab312a
commit
e68148f878
|
@ -2506,33 +2506,36 @@ size_t CDECL fwrite(const void *ptr, size_t size, size_t nmemb, FILE* file)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
_lock_file(file);
|
_lock_file(file);
|
||||||
|
|
||||||
|
while(wrcnt) {
|
||||||
if(file->_cnt) {
|
if(file->_cnt) {
|
||||||
int pcnt=((unsigned)file->_cnt>wrcnt)? wrcnt: file->_cnt;
|
int pcnt=((unsigned)file->_cnt>wrcnt)? wrcnt: file->_cnt;
|
||||||
memcpy(file->_ptr, ptr, pcnt);
|
memcpy(file->_ptr, ptr, pcnt);
|
||||||
file->_cnt -= pcnt;
|
file->_cnt -= pcnt;
|
||||||
file->_ptr += pcnt;
|
file->_ptr += pcnt;
|
||||||
written = pcnt;
|
written += pcnt;
|
||||||
wrcnt -= pcnt;
|
wrcnt -= pcnt;
|
||||||
ptr = (const char*)ptr + pcnt;
|
ptr = (const char*)ptr + pcnt;
|
||||||
} else if(!(file->_flag & _IOWRT)) {
|
} else if(!file->_bufsiz && (file->_flag & _IONBF)) {
|
||||||
if(file->_flag & _IORW) {
|
if(!(file->_flag & _IOWRT)) {
|
||||||
|
if(file->_flag & _IORW)
|
||||||
file->_flag |= _IOWRT;
|
file->_flag |= _IOWRT;
|
||||||
} else {
|
else
|
||||||
_unlock_file(file);
|
break;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(wrcnt) {
|
if(_write(file->_file, ptr, wrcnt) <= 0) {
|
||||||
/* Flush buffer */
|
|
||||||
int res=flush_buffer(file);
|
|
||||||
if(!res) {
|
|
||||||
int pwritten = _write(file->_file, ptr, wrcnt);
|
|
||||||
if (pwritten <= 0)
|
|
||||||
{
|
|
||||||
file->_flag |= _IOERR;
|
file->_flag |= _IOERR;
|
||||||
pwritten=0;
|
break;
|
||||||
}
|
}
|
||||||
written += pwritten;
|
written += wrcnt;
|
||||||
|
wrcnt = 0;
|
||||||
|
} else {
|
||||||
|
if(_flsbuf(*(const char*)ptr, file) == EOF)
|
||||||
|
break;
|
||||||
|
written++;
|
||||||
|
wrcnt--;
|
||||||
|
ptr = (const char*)ptr + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue