Piotr Caban : msvcrt: Change how fread splits reading into chunks.
Alexandre Julliard
julliard at winehq.org
Thu Nov 30 14:19:35 CST 2017
Module: wine
Branch: master
Commit: 1899eadf3eb4caaab26d5ff09e191d6da597224e
URL: http://source.winehq.org/git/wine.git/?a=commit;h=1899eadf3eb4caaab26d5ff09e191d6da597224e
Author: Piotr Caban <piotr at codeweavers.com>
Date: Thu Nov 30 19:55:16 2017 +0100
msvcrt: Change how fread splits reading into chunks.
It affects fd stream position and buffer content on unsuccessul reads.
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/msvcrt/file.c | 6 +++---
dlls/msvcrt/tests/file.c | 28 ++++++++++++++++++++++++++--
2 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 1e662e9..116a9bd 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -4300,7 +4300,7 @@ MSVCRT_size_t CDECL MSVCRT__fread_nolock(void *ptr, MSVCRT_size_t size, MSVCRT_s
while(rcnt>0)
{
int i;
- if (!file->_cnt && rcnt<MSVCRT_BUFSIZ && (file->_flag & (MSVCRT__IOMYBUF | MSVCRT__USERBUF))) {
+ if (!file->_cnt && rcnt<file->_bufsiz && (file->_flag & (MSVCRT__IOMYBUF | MSVCRT__USERBUF))) {
i = MSVCRT__read(file->_file, file->_base, file->_bufsiz);
file->_ptr = file->_base;
if (i != -1) {
@@ -4319,10 +4319,10 @@ MSVCRT_size_t CDECL MSVCRT__fread_nolock(void *ptr, MSVCRT_size_t size, MSVCRT_s
}
} else if (rcnt > INT_MAX) {
i = MSVCRT__read(file->_file, ptr, INT_MAX);
- } else if (rcnt < MSVCRT_BUFSIZ) {
+ } else if (rcnt < (file->_bufsiz ? file->_bufsiz : MSVCRT_INTERNAL_BUFSIZ)) {
i = MSVCRT__read(file->_file, ptr, rcnt);
} else {
- i = MSVCRT__read(file->_file, ptr, rcnt - MSVCRT_BUFSIZ/2);
+ i = MSVCRT__read(file->_file, ptr, rcnt - rcnt % (file->_bufsiz ? file->_bufsiz : MSVCRT_INTERNAL_BUFSIZ));
}
pread += i;
rcnt -= i;
diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c
index 00f5e7e..d4d63f2 100644
--- a/dlls/msvcrt/tests/file.c
+++ b/dlls/msvcrt/tests/file.c
@@ -222,7 +222,7 @@ static void test_readmode( BOOL ascii_mode )
static const char outbuffer[] = "0,1,2,3,4,5,6,7,8,9\r\n\r\nA,B,C,D,E\r\nX,Y,Z";
static const char padbuffer[] = "ghjghjghjghj";
static const char nlbuffer[] = "\r\n";
- char buffer[2*BUFSIZ+256];
+ static char buffer[8192];
const char *optr;
int fd;
FILE *file;
@@ -327,7 +327,7 @@ static void test_readmode( BOOL ascii_mode )
ok(feof(file)==0,"feof failure in %s\n", IOMODE);
ok(fread(buffer,2,1,file)==0,"fread failure in %s\n",IOMODE);
ok(feof(file)!=0,"feof failure in %s\n", IOMODE);
-
+
/* test some additional functions */
rewind(file);
ok(ftell(file) == 0,"Did not start at beginning of file in %s\n", IOMODE);
@@ -350,6 +350,30 @@ static void test_readmode( BOOL ascii_mode )
fclose (file);
unlink ("fdopen.tst");
+
+ /* test INTERNAL_BUFSIZ read containing 0x1a character (^Z) */
+ fd = open("fdopen.tst", O_WRONLY | O_CREAT | O_BINARY, _S_IREAD |_S_IWRITE);
+ ok(fd != -1, "open failed\n");
+ memset(buffer, 'a', sizeof(buffer));
+ buffer[1] = 0x1a;
+ ok(write(fd, buffer, sizeof(buffer)) == sizeof(buffer), "write failed\n");
+ ok(close(fd) != -1, "close failed\n");
+
+ fd = open("fdopen.tst", O_RDONLY);
+ ok(fd != -1, "open failed\n");
+ file = fdopen(fd, ascii_mode ? "r" : "rb");
+ ok(file != NULL, "fdopen failed\n");
+
+ memset(buffer, 0, sizeof(buffer));
+ i = fread(buffer, 4096, 1, file);
+ ok(!i, "fread succeeded\n");
+ ok(file->_bufsiz == 4096, "file->_bufsiz = %d\n", file->_bufsiz);
+ for(i=0; i<4096; i++)
+ if(buffer[i] != (i==1 ? 0x1a : 'a')) break;
+ ok(i==4096, "buffer[%d] = %d\n", i, buffer[i]);
+
+ fclose(file);
+ unlink("fdopen.tst");
}
static void test_asciimode(void)
More information about the wine-cvs
mailing list