Commit b44ea808 authored by Duane Clark's avatar Duane Clark Committed by Alexandre Julliard

msvcrt: Fix fread.

parent b37b967a
...@@ -2490,6 +2490,8 @@ MSVCRT_size_t CDECL MSVCRT_fread(void *ptr, MSVCRT_size_t size, MSVCRT_size_t nm ...@@ -2490,6 +2490,8 @@ MSVCRT_size_t CDECL MSVCRT_fread(void *ptr, MSVCRT_size_t size, MSVCRT_size_t nm
memcpy(ptr, file->_ptr, pcnt); memcpy(ptr, file->_ptr, pcnt);
file->_cnt -= pcnt; file->_cnt -= pcnt;
file->_ptr += pcnt; file->_ptr += pcnt;
if (MSVCRT_fdesc[file->_file].wxflag & WX_TEXT)
pcnt -= remove_cr(ptr,pcnt);
read += pcnt ; read += pcnt ;
rcnt -= pcnt ; rcnt -= pcnt ;
ptr = (char*)ptr + pcnt; ptr = (char*)ptr + pcnt;
...@@ -2499,18 +2501,22 @@ MSVCRT_size_t CDECL MSVCRT_fread(void *ptr, MSVCRT_size_t size, MSVCRT_size_t nm ...@@ -2499,18 +2501,22 @@ MSVCRT_size_t CDECL MSVCRT_fread(void *ptr, MSVCRT_size_t size, MSVCRT_size_t nm
} else } else
return 0; return 0;
} }
if(rcnt) while(rcnt>0)
{ {
pread = _read(file->_file,ptr, rcnt); int i = _read(file->_file,ptr, rcnt);
if (i==0) break;
pread += i;
rcnt -= i;
/* expose feof condition in the flags /* expose feof condition in the flags
* MFC tests file->_flag for feof, and doesn't not call feof()) * MFC tests file->_flag for feof, and doesn't not call feof())
*/ */
if ( MSVCRT_fdesc[file->_file].wxflag & WX_ATEOF) if ( MSVCRT_fdesc[file->_file].wxflag & WX_ATEOF)
file->_flag |= MSVCRT__IOEOF; file->_flag |= MSVCRT__IOEOF;
else if (pread == -1) else if (i == -1)
{ {
file->_flag |= MSVCRT__IOERR; file->_flag |= MSVCRT__IOERR;
pread = 0; pread = 0;
rcnt = 0;
} }
} }
read+=pread; read+=pread;
......
...@@ -210,9 +210,6 @@ static void test_readmode( BOOL ascii_mode ) ...@@ -210,9 +210,6 @@ static void test_readmode( BOOL ascii_mode )
ok(fgets(buffer,MSVCRT_BUFSIZ-6,file) !=0,"padding line fgets failed unexpected in %s\n", IOMODE); ok(fgets(buffer,MSVCRT_BUFSIZ-6,file) !=0,"padding line fgets failed unexpected in %s\n", IOMODE);
j=strlen(outbuffer); j=strlen(outbuffer);
i=fread(buffer,1,256,file); i=fread(buffer,1,256,file);
if (ao == -1)
todo_wine todo_wine ok(i==j+6+ao*4,"fread failed, expected %d got %d in %s\n", j+6+ao*4, i, IOMODE);
else
ok(i==j+6+ao*4,"fread failed, expected %d got %d in %s\n", j+6+ao*4, i, IOMODE); ok(i==j+6+ao*4,"fread failed, expected %d got %d in %s\n", j+6+ao*4, i, IOMODE);
l = ftell(file); l = ftell(file);
ok(l == pl+j+1,"ftell after fread got %ld should be %d in %s\n", l, pl+j+1, IOMODE); ok(l == pl+j+1,"ftell after fread got %ld should be %d in %s\n", l, pl+j+1, IOMODE);
...@@ -222,9 +219,6 @@ static void test_readmode( BOOL ascii_mode ) ...@@ -222,9 +219,6 @@ static void test_readmode( BOOL ascii_mode )
ok(fgets(buffer,MSVCRT_BUFSIZ-6,file) !=0,"padding line fgets failed unexpected in %s\n", IOMODE); ok(fgets(buffer,MSVCRT_BUFSIZ-6,file) !=0,"padding line fgets failed unexpected in %s\n", IOMODE);
j = fp+10; j = fp+10;
i=fread(buffer,1,j,file); i=fread(buffer,1,j,file);
if (ao == -1)
todo_wine ok(i==j,"fread failed, expected %d got %d in %s\n", j, i, IOMODE);
else
ok(i==j,"fread failed, expected %d got %d in %s\n", j, i, IOMODE); ok(i==j,"fread failed, expected %d got %d in %s\n", j, i, IOMODE);
/* test some additional functions */ /* test some additional functions */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment