Module: wine Branch: master Commit: 0d16965832f2d43a9d0592a8c37233acece90d78 URL: http://source.winehq.org/git/wine.git/?a=commit;h=0d16965832f2d43a9d0592a8c3...
Author: Uwe Bonnes bon@elektron.ikp.physik.tu-darmstadt.de Date: Thu Jan 28 12:51:12 2010 +0100
msvcrt: read_i should pull in LF after CR only in unbuffered mode.
---
dlls/msvcrt/file.c | 12 ++++++++++-- dlls/msvcrt/tests/file.c | 18 +++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index d7e628b..9dc1b54 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -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; diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index 18247ad..5afdfcb 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -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);