Module: wine Branch: master Commit: 089cc7818299c0d8f6a2fa726d205db25aad895f URL: http://source.winehq.org/git/wine.git/?a=commit;h=089cc7818299c0d8f6a2fa726d...
Author: Piotr Caban piotr@codeweavers.com Date: Wed Aug 21 13:52:26 2013 +0200
msvcrt: Fix lookahead buffer usage on pipes.
---
dlls/msvcrt/file.c | 12 ++++++++++-- dlls/msvcrt/tests/file.c | 9 +++++---- 2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 0df95d9..871027d 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -2571,8 +2571,16 @@ static int read_i(int fd, void *buf, unsigned int count)
if (fdinfo->wxflag & (WX_PIPE | WX_NOSEEK)) { - fdinfo->lookahead[0] = lookahead[0]; - fdinfo->lookahead[1] = lookahead[1]; + if (lookahead[0]=='\n' && (!utf16 || !lookahead[1])) + { + bufstart[j++] = '\n'; + if (utf16) bufstart[j++] = 0; + } + else + { + fdinfo->lookahead[0] = lookahead[0]; + fdinfo->lookahead[1] = lookahead[1]; + } } else SetFilePointer(fdinfo->handle, -1-utf16, NULL, FILE_CURRENT); diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index fc92272..7a3253a 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -2032,8 +2032,8 @@ static void test_pipes(const char* selfname) ok(0, "pipe failed with errno %d\n", errno); return; } - r = write(pipes[1], "\r\n\rab", 5); - ok(r == 5, "write returned %d, errno = %d\n", r, errno); + r = write(pipes[1], "\r\n\rab\r\n", 7); + ok(r == 7, "write returned %d, errno = %d\n", r, errno); setmode(pipes[0], O_TEXT); r = read(pipes[0], buf, 1); ok(r == 1, "read returned %d, expected 1\n", r); @@ -2044,9 +2044,10 @@ static void test_pipes(const char* selfname) r = read(pipes[0], buf, 1); ok(r == 1, "read returned %d, expected 1\n", r); ok(buf[0] == 'a', "buf[0] = %x, expected 'a'\n", buf[0]); - r = read(pipes[0], buf, 1); - ok(r == 1, "read returned %d, expected 1\n", r); + r = read(pipes[0], buf, 2); + ok(r == 2, "read returned %d, expected 1\n", r); ok(buf[0] == 'b', "buf[0] = %x, expected 'b'\n", buf[0]); + ok(buf[1] == '\n', "buf[1] = %x, expected '\n'\n", buf[1]);
if (p_fopen_s) {