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
memcpy(ptr, file->_ptr, pcnt);
file->_cnt -= pcnt;
file->_ptr += pcnt;
if (MSVCRT_fdesc[file->_file].wxflag & WX_TEXT)
pcnt -= remove_cr(ptr,pcnt);
read += pcnt ;
rcnt -= 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
} else
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
* MFC tests file->_flag for feof, and doesn't not call feof())
*/
if ( MSVCRT_fdesc[file->_file].wxflag & WX_ATEOF)
file->_flag |= MSVCRT__IOEOF;
else if (pread == -1)
else if (i == -1)
{
file->_flag |= MSVCRT__IOERR;
pread = 0;
rcnt = 0;
}
}
read+=pread;
......
......@@ -210,10 +210,7 @@ static void test_readmode( BOOL ascii_mode )
ok(fgets(buffer,MSVCRT_BUFSIZ-6,file) !=0,"padding line fgets failed unexpected in %s\n", IOMODE);
j=strlen(outbuffer);
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);
ok(l == pl+j+1,"ftell after fread got %ld should be %d in %s\n", l, pl+j+1, IOMODE);
/* fread should return the requested number of bytes if available */
......@@ -222,10 +219,7 @@ static void test_readmode( BOOL ascii_mode )
ok(fgets(buffer,MSVCRT_BUFSIZ-6,file) !=0,"padding line fgets failed unexpected in %s\n", IOMODE);
j = fp+10;
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 */
rewind(file);
......
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