Markus Amsler : msvcrt: fread: Fill buffer on small reads.
Alexandre Julliard
julliard at wine.codeweavers.com
Fri Oct 13 05:25:44 CDT 2006
Module: wine
Branch: master
Commit: fdd61a7a35f27ff2e3327bc5c718ea7c63a1e08a
URL: http://source.winehq.org/git/wine.git/?a=commit;h=fdd61a7a35f27ff2e3327bc5c718ea7c63a1e08a
Author: Markus Amsler <markus.amsler at oribi.org>
Date: Fri Oct 13 00:03:29 2006 +0200
msvcrt: fread: Fill buffer on small reads.
---
dlls/msvcrt/file.c | 24 +++++++++++++++++++++++-
1 files changed, 23 insertions(+), 1 deletions(-)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 1e72cef..6314210 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -2524,7 +2524,29 @@ MSVCRT_size_t CDECL MSVCRT_fread(void *p
}
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<rcnt) ? file->_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
More information about the wine-cvs
mailing list