Module: wine Branch: refs/heads/master Commit: 4d3952f3dc2b54a256726d5693adabcbefcc34d9 URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=4d3952f3dc2b54a256726d56...
Author: Duane Clark fpga@pacbell.net Date: Tue Aug 8 16:08:05 2006 -0700
msvcrt: In text mode a ctrl-z signals EOF.
Spotted by David Hagood with test suggested by Dan Kegel.
---
dlls/msvcrt/file.c | 13 ++++++++++++ dlls/msvcrt/tests/file.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 9fe09dd..ba5b445 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -1634,6 +1634,19 @@ static int read_i(int fd, void *buf, uns */ if (ReadFile(hand, bufstart, count, &num_read, NULL)) { + if (MSVCRT_fdesc[fd].wxflag & WX_TEXT) + { + int i; + /* in text mode, a ctrl-z signals EOF */ + for (i=0; i<num_read; i++) + { + if (bufstart[i] == 0x1a) + { + num_read = i; + break; + } + } + } if (num_read != count) { MSVCRT_fdesc[fd].wxflag |= WX_ATEOF; diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index 0205de4..470a9e9 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -372,6 +372,53 @@ #define LLEN 512 unlink(tempf); }
+static void test_ctrlz( void ) +{ + char* tempf; + FILE *tempfh; + static const char mytext[]= "This is test_ctrlz"; + char buffer[256]; + int i, j; + long l; + + tempf=_tempnam(".","wne"); + tempfh = fopen(tempf,"wb"); + fputs(mytext,tempfh); + j = 0x1a; /* a ctrl-z character signals EOF in text mode */ + fputc(j,tempfh); + j = '\r'; + fputc(j,tempfh); + j = '\n'; + fputc(j,tempfh); + j = 'a'; + fputc(j,tempfh); + fclose(tempfh); + tempfh = fopen(tempf,"rt"); /* open in TEXT mode */ + ok(fgets(buffer,256,tempfh) != 0,"fgets failed unexpected\n"); + i=strlen(buffer); + j=strlen(mytext); + ok(i==j, "returned string length expected %d got %d\n", j, i); + j+=4; /* ftell should indicate the true end of file */ + l=ftell(tempfh); + ok(l==j, "ftell expected %d got %ld\n", j, l); + ok(feof(tempfh), "did not get EOF\n"); + fclose(tempfh); + + tempfh = fopen(tempf,"rb"); /* open in BINARY mode */ + ok(fgets(buffer,256,tempfh) != 0,"fgets failed unexpected\n"); + i=strlen(buffer); + j=strlen(mytext)+3; /* should get through newline */ + ok(i==j, "returned string length expected %d got %d\n", j, i); + l=ftell(tempfh); + ok(l==j, "ftell expected %d got %ld\n", j, l); + ok(fgets(buffer,256,tempfh) != 0,"fgets failed unexpected\n"); + i=strlen(buffer); + ok(i==1, "returned string length expected %d got %d\n", 1, i); + ok(feof(tempfh), "did not get EOF\n"); + fclose(tempfh); + unlink(tempf); +} + static void test_file_put_get( void ) { char* tempf; @@ -727,6 +774,7 @@ START_TEST(file) test_readmode(FALSE); /* binary mode */ test_readmode(TRUE); /* ascii mode */ test_fgetwc(); + test_ctrlz(); test_file_put_get(); test_tmpnam(); test_get_osfhandle();