msvcrt: read_i should pull in LF after CR only in unbuffered mode.

This commit is contained in:
Uwe Bonnes 2010-01-28 12:51:12 +01:00 committed by Alexandre Julliard
parent 92ac665d37
commit 0d16965832
2 changed files with 27 additions and 3 deletions

View File

@ -1786,8 +1786,16 @@ static int read_i(int fd, void *buf, unsigned int count)
DWORD i, j;
if (bufstart[num_read-1] == '\r')
{
MSVCRT_fdesc[fd].wxflag |= WX_READCR;
num_read--;
if(count == 1)
{
MSVCRT_fdesc[fd].wxflag &= ~WX_READCR;
ReadFile(hand, bufstart, 1, &num_read, NULL);
}
else
{
MSVCRT_fdesc[fd].wxflag |= WX_READCR;
num_read--;
}
}
else
MSVCRT_fdesc[fd].wxflag &= ~WX_READCR;

View File

@ -880,7 +880,23 @@ static void test_file_write_read( void )
"problems with _O_BINARY _write / _O_TEXT _read\n");
_close(tempfd);
ret =_chmod (tempf, _S_IREAD | _S_IWRITE);
/* test _read with single bytes. CR should be skipped and LF pulled in */
tempfd = _open(tempf,_O_RDONLY|_O_TEXT); /* open in TEXT mode */
for (i=0; i<strlen(mytext); i++) /* */
{
_read(tempfd,btext, 1);
ok(btext[0] == mytext[i],"_read failed at pos %d 0x%02x vs 0x%02x\n", i, btext[0], mytext[i]);
}
while (_read(tempfd,btext, 1));
_close(tempfd);
/* test _read in buffered mode. Last CR should be skipped but LF not pulled in */
tempfd = _open(tempf,_O_RDONLY|_O_TEXT); /* open in TEXT mode */
i = _read(tempfd,btext, strlen(mytext));
ok(i == strlen(mytext)-1, "_read_i %d vs %d\n", i, strlen(mytext));
_close(tempfd);
ret =_chmod (tempf, _S_IREAD | _S_IWRITE);
ok( ret == 0,
"Can't chmod '%s' to read-write: %d\n", tempf, errno);
ret = unlink(tempf);