From: Bartosz Kosiorek gang65@poczta.onet.pl
--- dlls/msvcrt/file.c | 2 +- dlls/msvcrt/tests/file.c | 36 ++++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 7cccf96b1c7..97aa8238018 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -2932,7 +2932,7 @@ static int read_i(int fd, ioinfo *fdinfo, void *buf, unsigned int count) }
utf16 = ioinfo_get_textmode(fdinfo) == TEXTMODE_UTF16LE; - if (ioinfo_get_textmode(fdinfo) != TEXTMODE_ANSI && count&1) + if (ioinfo_get_textmode(fdinfo) != TEXTMODE_ANSI && count & 1) { *_errno() = EINVAL; return -1; diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index 71b3e1399f8..2cb6e797960 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -248,7 +248,7 @@ static void test_readmode( BOOL ascii_mode )
fd = open ("fdopen.tst", O_WRONLY | O_CREAT | O_BINARY, _S_IREAD |_S_IWRITE); /* an internal buffer of BUFSIZ is maintained, so make a file big - * enough to test operations that cross the buffer boundary + * enough to test operations that cross the buffer boundary */ j = (2*BUFSIZ-4)/strlen(padbuffer); for (i=0; i<j; i++) @@ -266,7 +266,7 @@ static void test_readmode( BOOL ascii_mode ) ok(_doserrno == ERROR_ACCESS_DENIED, "doserrno = %ld\n", _doserrno);
close (fd); - + fd = open ("fdopen.tst", O_RDONLY, _S_IREAD |_S_IWRITE); errno = 0xdeadbeef; ok(dup2(fd, -1) == -1, "dup2(fd, -1) succeeded\n"); @@ -284,7 +284,7 @@ static void test_readmode( BOOL ascii_mode ) file = fdopen (fd, "rb"); ao = 0; } - + /* 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,2*BUFSIZ+256,file) !=0,"padding line fgets failed unexpected in %s\n", IOMODE); @@ -323,7 +323,7 @@ static void test_readmode( BOOL ascii_mode ) ok(write(fd, buffer, 1) == -1, "read succeeded on write-only file\n"); ok(errno == EBADF, "errno = %d\n", errno); ok(_doserrno == ERROR_ACCESS_DENIED, "doserrno = %ld\n", _doserrno); - + /* test fread across buffer boundary */ rewind(file); ok(ftell(file) == 0,"Did not start at beginning of file in %s\n", IOMODE); @@ -829,7 +829,7 @@ static void test_fgetwc( void ) ok(*wptr == '\n', "Carriage return was not skipped\n"); fclose(tempfh); unlink(tempf); - + tempfh = fopen(tempf,"wb"); j = 'a'; /* pad to almost the length of the internal buffer. Use an odd number of bytes @@ -1290,7 +1290,7 @@ static void test_ctrlz( void ) 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); @@ -1506,7 +1506,7 @@ static void test_file_write_read( void ) errno = 0xdeadbeef; ret = _read(tempfd, btext, 3); ok(ret == -1, "_read returned %d, expected -1\n", ret); - ok(errno == 22, "errno = %d\n", errno); + ok(errno == EINVAL, "errno = %d\n", errno); ret = _read(tempfd, btext, sizeof(btext)); ok(ret == 6, "_read returned %d, expected 6\n", ret); ok(!memcmp(btext, "\x61\x00\n\x00\xff\xff", 6), "btext is incorrect\n"); @@ -1517,7 +1517,7 @@ static void test_file_write_read( void ) errno = 0xdeadbeef; ret = _write(tempfd, "a", 1); ok(ret == -1, "_write returned %d, expected -1\n", ret); - ok(errno == 22, "errno = %d\n", errno); + ok(errno == EINVAL, "errno = %d\n", errno); ret = _write(tempfd, "a\x00\n\x00\x62\x00", 6); ok(ret == 6, "_write returned %d, expected 6\n", ret); _close(tempfd); @@ -1536,9 +1536,17 @@ static void test_file_write_read( void ) ok(!memcmp(btext, "\x61\x00\n\x00\x62\x00", 6), "btext is incorrect\n");
/* when buffer is small read sometimes fails in native implementation */ + errno = 0xdeadbeef; lseek(tempfd, 3 /* skip bom */, SEEK_SET); ret = _read(tempfd, btext, 4); todo_wine ok(ret == -1, "_read returned %d, expected -1\n", ret); + ok(errno == EBADF, "Wrong value of errno = %d\n", errno); + + lseek(tempfd, 6, SEEK_SET); + ret = _read(tempfd, btext, 5); /* Odd number of UTF characters */ + ok(ret == 2, "_read returned %d, expected 2\n", ret); + ok(!memcmp(btext, "\x62\x00", 2), "btext is incorrect\n"); + _close(tempfd);
lseek(tempfd, 6, SEEK_SET); ret = _read(tempfd, btext, 2); @@ -1613,7 +1621,7 @@ static void test_file_inherit_child_no(const char* fd_s) int ret;
ret = write(fd, "Success", 8); - ok( ret == -1 && errno == EBADF, + ok( ret == -1 && errno == EBADF, "Wrong write result in child process on %d (%s)\n", fd, strerror(errno)); }
@@ -1729,7 +1737,7 @@ static void test_file_inherit( const char* selfname ) ok(read(fd, buffer, sizeof (buffer)) == 8 && memcmp(buffer, "Success", 8) == 0, "Couldn't read back the data\n"); close (fd); ok(unlink("fdopen.tst") == 0, "Couldn't unlink\n"); - + fd = open ("fdopen.tst", O_CREAT | O_RDWR | O_BINARY | O_NOINHERIT, _S_IREAD |_S_IWRITE); ok(fd != -1, "Couldn't create test file\n"); arg_v[1] = "file"; @@ -1978,7 +1986,7 @@ static void test_chsize( void ) LONG cur, pos, count; char temptext[] = "012345678"; char *tempfile = _tempnam( ".", "tst" ); - + ok( tempfile != NULL, "Couldn't create test file: %s\n", tempfile );
fd = _open( tempfile, _O_CREAT|_O_TRUNC|_O_RDWR, _S_IREAD|_S_IWRITE ); @@ -1998,7 +2006,7 @@ static void test_chsize( void ) ok( _filelength( fd ) == sizeof(temptext) / 2, "Wrong file size\n" );
/* enlarge the file */ - ok( _chsize( fd, sizeof(temptext) * 2 ) == 0, "_chsize() failed\n" ); + ok( _chsize( fd, sizeof(temptext) * 2 ) == 0, "_chsize() failed\n" );
pos = _lseek( fd, 0, SEEK_CUR ); ok( cur == pos, "File pointer changed from: %ld to: %ld\n", cur, pos ); @@ -2033,7 +2041,7 @@ static void test_fopen_fclose_fcloseall( void ) "filename is empty, errno = %d (expected 2 or 22)\n", errno); errno = 0xfaceabad; stream4 = fopen(NULL, "w+"); - ok(stream4 == NULL && (errno == EINVAL || errno == ENOENT), + ok(stream4 == NULL && (errno == EINVAL || errno == ENOENT), "filename is NULL, errno = %d (expected 2 or 22)\n", errno);
/* testing fclose() */ @@ -2793,7 +2801,7 @@ static void test_close(void) errno = 0xdeadbeef; ret1 = close(fd1); ok(ret1 == -1, "close(fd1) succeeded\n"); - ok(errno == 9, "errno = %d\n", errno); + ok(errno == EBADF, "errno = %d\n", errno);
/* test close on stdout and stderr that use the same handle */ h = CreateFileA("fdopen.tst", GENERIC_READ|GENERIC_WRITE,