From fdd61a7a35f27ff2e3327bc5c718ea7c63a1e08a Mon Sep 17 00:00:00 2001 From: Markus Amsler Date: Fri, 13 Oct 2006 00:03:29 +0200 Subject: [PATCH] msvcrt: fread: Fill buffer on small reads. --- dlls/msvcrt/file.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 1e72cef6b20..6314210dd00 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -2524,7 +2524,29 @@ MSVCRT_size_t CDECL MSVCRT_fread(void *ptr, MSVCRT_size_t size, MSVCRT_size_t nm } while(rcnt>0) { - int i = _read(file->_file,ptr, rcnt); + int i; + /* Fill the buffer on small reads. + * TODO: Use a better buffering strategy. + */ + if (!file->_cnt && size*nmemb <= MSVCRT_BUFSIZ/2 && !(file->_flag & MSVCRT__IONBF)) { + if (file->_bufsiz == 0) { + msvcrt_alloc_buffer(file); + } + file->_cnt = _read(file->_file, file->_base, file->_bufsiz); + file->_ptr = file->_base; + i = (file->_cnt_cnt : rcnt; + /* If the buffer fill reaches eof but fread wouldn't, clear eof. */ + if (i > 0 && i < file->_cnt) { + MSVCRT_fdesc[file->_file].wxflag &= ~WX_ATEOF; + } + if (i > 0) { + memcpy(ptr, file->_ptr, i); + file->_cnt -= i; + file->_ptr += i; + } + } else { + i = _read(file->_file,ptr, rcnt); + } pread += i; rcnt -= i; /* expose feof condition in the flags