dll/msvcrt/file.c : fseek/feof fix
Erik de Castro Lopo
mle+win at mega-nerd.com
Tue Apr 8 06:53:53 CDT 2008
Hi all,
I have found a bug in MSVCRT_fseek. If I fread() to the end of a
file, then do fseek (file, 0, SEEK_SET), the feof() function still
returns true.
According to the ISO standard
A successful call to fseek() shall clear the end-of-file indicator
for the stream and undo any effects of ungetc() and ungetwc() on
the same stream. After an fseek() call, the next operation on an
update stream may be either input or output.
I also found a test in dlls/msvcrt/tests/file.c that seems to have
been made inactive by use of a "todo_wine". Activating the test
without the fix results in two failures:
file.c:244: Test failed: feof failure in binary mode
file.c:244: Test failed: feof failure in ascii mode
Finally, I also wrote a small test program that tested this
functionality and ran it on windows XP. This confirmed that the
current behaviour of wine is different from XP and that the
behaviour with my fix matches XP.
Patch below.
Cheers,
Erik
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 0c1e84b..866d28d 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -918,6 +918,8 @@ int CDECL MSVCRT_fseek(MSVCRT_FILE* file, long offset, int whence)
if(file->_flag & MSVCRT__IORW) {
file->_flag &= ~(MSVCRT__IOREAD|MSVCRT__IOWRT);
}
+ /* Clear end of file flag */
+ file->_flag &= ~MSVCRT__IOEOF;
return (_lseek(file->_file,offset,whence) == -1)?-1:0;
}
diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c
index d406ae5..aa58a32 100644
--- a/dlls/msvcrt/tests/file.c
+++ b/dlls/msvcrt/tests/file.c
@@ -241,7 +241,7 @@ static void test_readmode( BOOL ascii_mode )
ok(fread(buffer,1,1,file)==0,"fread failure in %s\n", IOMODE);
ok(feof(file)!=0,"feof failure in %s\n", IOMODE);
ok(fseek(file,-3,SEEK_CUR)==0,"seek failure in %s\n", IOMODE);
- todo_wine ok(feof(file)==0,"feof failure in %s\n", IOMODE);
+ ok(feof(file)==0,"feof failure in %s\n", IOMODE);
ok(fread(buffer,2,1,file)==1,"fread failed in %s\n", IOMODE);
ok(feof(file)==0,"feof failure in %s\n", IOMODE);
ok(fread(buffer,2,1,file)==0,"fread failure in %s\n",IOMODE);
--
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
"Properly read, the Bible is the most potent force for atheism
ever conceived" -- Isaac Asimov
More information about the wine-patches
mailing list