msvcrt: Fix fread on large buffers in ascii mode.
This commit is contained in:
parent
9635e9415a
commit
b4c1c67ea4
|
@ -2550,8 +2550,9 @@ MSVCRT_size_t CDECL MSVCRT_fread(void *ptr, MSVCRT_size_t size, MSVCRT_size_t nm
|
|||
}
|
||||
pread += i;
|
||||
rcnt -= i;
|
||||
ptr = (char *)ptr+i;
|
||||
/* 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 call feof())
|
||||
*/
|
||||
if ( MSVCRT_fdesc[file->_file].wxflag & WX_ATEOF)
|
||||
file->_flag |= MSVCRT__IOEOF;
|
||||
|
|
|
@ -139,20 +139,20 @@ 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[MSVCRT_BUFSIZ+256];
|
||||
char buffer[2*MSVCRT_BUFSIZ+256], *optr;
|
||||
int fd;
|
||||
FILE *file;
|
||||
int i, j, fp, ao, *ip, pl;
|
||||
int i, j, m, fp, ao, *ip, pl;
|
||||
long l;
|
||||
|
||||
fd = open ("fdopen.tst", O_WRONLY | O_CREAT | O_BINARY, _S_IREAD |_S_IWRITE);
|
||||
/* an internal buffer of MSVCRT_BUFSIZ is maintained, so make a file big
|
||||
* enough to test operations that cross the buffer boundary
|
||||
*/
|
||||
j = (MSVCRT_BUFSIZ-4)/strlen(padbuffer);
|
||||
j = (2*MSVCRT_BUFSIZ-4)/strlen(padbuffer);
|
||||
for (i=0; i<j; i++)
|
||||
write (fd, padbuffer, strlen(padbuffer));
|
||||
j = (MSVCRT_BUFSIZ-4)%strlen(padbuffer);
|
||||
j = (2*MSVCRT_BUFSIZ-4)%strlen(padbuffer);
|
||||
for (i=0; i<j; i++)
|
||||
write (fd, &padbuffer[i], 1);
|
||||
write (fd, nlbuffer, strlen(nlbuffer));
|
||||
|
@ -173,9 +173,9 @@ static void test_readmode( BOOL ascii_mode )
|
|||
|
||||
/* first is a test of fgets, ftell, fseek */
|
||||
ok(ftell(file) == 0,"Did not start at beginning of file in %s\n", IOMODE);
|
||||
ok(fgets(buffer,MSVCRT_BUFSIZ+256,file) !=0,"padding line fgets failed unexpected in %s\n", IOMODE);
|
||||
ok(fgets(buffer,2*MSVCRT_BUFSIZ+256,file) !=0,"padding line fgets failed unexpected in %s\n", IOMODE);
|
||||
l = ftell(file);
|
||||
pl = MSVCRT_BUFSIZ-2;
|
||||
pl = 2*MSVCRT_BUFSIZ-2;
|
||||
ok(l == pl,"padding line ftell got %ld should be %d in %s\n", l, pl, IOMODE);
|
||||
ok(lstrlenA(buffer) == pl+ao,"padding line fgets got size %d should be %d in %s\n",
|
||||
lstrlenA(buffer), pl+ao, IOMODE);
|
||||
|
@ -209,10 +209,20 @@ static void test_readmode( BOOL ascii_mode )
|
|||
ok(ftell(file) == 0,"Did not start at beginning of file in %s\n", IOMODE);
|
||||
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);
|
||||
ok(i==j+6+ao*4,"fread failed, expected %d got %d in %s\n", j+6+ao*4, i, IOMODE);
|
||||
i=fread(buffer,1,MSVCRT_BUFSIZ+strlen(outbuffer),file);
|
||||
ok(i==MSVCRT_BUFSIZ+j,"fread failed, expected %d got %d in %s\n", MSVCRT_BUFSIZ+j, 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);
|
||||
ok(l == pl+j-(ao*4)-5,"ftell after fread got %ld should be %d in %s\n", l, pl+j-(ao*4)-5, IOMODE);
|
||||
for (m=0; m<3; m++)
|
||||
ok(buffer[m]==padbuffer[m+(MSVCRT_BUFSIZ-4)%strlen(padbuffer)],"expected %c got %c\n", padbuffer[m], buffer[m]);
|
||||
m+=MSVCRT_BUFSIZ+2+ao;
|
||||
optr = (char *)outbuffer;
|
||||
for (; m<i; m++) {
|
||||
ok(buffer[m]==*optr,"char %d expected %c got %c in %s\n", m, *optr, buffer[m], IOMODE);
|
||||
optr++;
|
||||
if (ao && (*optr == '\r'))
|
||||
optr++;
|
||||
}
|
||||
/* fread should return the requested number of bytes if available */
|
||||
rewind(file);
|
||||
ok(ftell(file) == 0,"Did not start at beginning of file in %s\n", IOMODE);
|
||||
|
@ -235,7 +245,7 @@ static void test_readmode( BOOL ascii_mode )
|
|||
/* test some additional functions */
|
||||
rewind(file);
|
||||
ok(ftell(file) == 0,"Did not start at beginning of file in %s\n", IOMODE);
|
||||
ok(fgets(buffer,MSVCRT_BUFSIZ+256,file) !=0,"padding line fgets failed unexpected in %s\n", IOMODE);
|
||||
ok(fgets(buffer,2*MSVCRT_BUFSIZ+256,file) !=0,"padding line fgets failed unexpected in %s\n", IOMODE);
|
||||
i = _getw(file);
|
||||
ip = (int *)outbuffer;
|
||||
ok(i == *ip,"_getw failed, expected %08x got %08x in %s\n", *ip, i, IOMODE);
|
||||
|
|
Loading…
Reference in New Issue