mirror of
https://github.com/reactos/reactos.git
synced 2025-06-23 10:50:16 +00:00
[CRT]
* Update fwrite(). * Fixes some msvcrt:file tests. CORE-8540 svn path=/trunk/; revision=64738
This commit is contained in:
parent
0c4ba28402
commit
628b200fa4
1 changed files with 29 additions and 11 deletions
|
@ -2972,28 +2972,46 @@ size_t CDECL fwrite(const void *ptr, size_t size, size_t nmemb, FILE* file)
|
||||||
_lock_file(file);
|
_lock_file(file);
|
||||||
|
|
||||||
while(wrcnt) {
|
while(wrcnt) {
|
||||||
|
#ifndef __REACTOS__
|
||||||
|
if(file->_cnt < 0) {
|
||||||
|
WARN("negative file->_cnt value in %p\n", file);
|
||||||
|
file->_flag |= MSVCRT__IOERR;
|
||||||
|
break;
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
if(file->_cnt) {
|
if(file->_cnt) {
|
||||||
int pcnt=((unsigned)file->_cnt>wrcnt)? wrcnt: file->_cnt;
|
int pcnt=(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->_bufsiz && (file->_flag & _IONBF)) {
|
} else if((file->_flag & _IONBF)
|
||||||
if(!(file->_flag & _IOWRT)) {
|
|| ((file->_flag & (_IOMYBUF | _USERBUF)) && wrcnt >= file->_bufsiz)
|
||||||
if(file->_flag & _IORW)
|
|| (!(file->_flag & (_IOMYBUF | _USERBUF)) && wrcnt >= MSVCRT_INTERNAL_BUFSIZ)) {
|
||||||
file->_flag |= _IOWRT;
|
size_t pcnt;
|
||||||
else
|
int bufsiz;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(_write(file->_file, ptr, wrcnt) <= 0) {
|
if(file->_flag & _IONBF)
|
||||||
|
bufsiz = 1;
|
||||||
|
else if(!(file->_flag & (_IOMYBUF | _USERBUF)))
|
||||||
|
bufsiz = MSVCRT_INTERNAL_BUFSIZ;
|
||||||
|
else
|
||||||
|
bufsiz = file->_bufsiz;
|
||||||
|
|
||||||
|
pcnt = (wrcnt / bufsiz) * bufsiz;
|
||||||
|
|
||||||
|
if(flush_buffer(file) == EOF)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(_write(file->_file, ptr, pcnt) <= 0) {
|
||||||
file->_flag |= _IOERR;
|
file->_flag |= _IOERR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
written += wrcnt;
|
written += pcnt;
|
||||||
wrcnt = 0;
|
wrcnt -= pcnt;
|
||||||
|
ptr = (const char*)ptr + pcnt;
|
||||||
} else {
|
} else {
|
||||||
if(_flsbuf(*(const char*)ptr, file) == EOF)
|
if(_flsbuf(*(const char*)ptr, file) == EOF)
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue