Maybe this is a bug of MinGW-w64.
We have our own implementation of _ftelli64 for msvcrt.dll in libmingwex, 
because msvcrt.dll does not export it.

Workaround:
You can use ucrtbase.dll as C Runtime instead of msvcrt.dll.
Ucrtbase.dll exports _ftelli64.

Windows 10 版のメ�`ル<https://go.microsoft.com/fwlink/?LinkId=550986>から送信

差出人: Etienne Sandré-Chardonnal<mailto:[email protected]>
送信日�r: 2017年10月19日 17:54
宛先: 
[email protected]<mailto:[email protected]>
件名: Re: [Mingw-w64-public] _ftelli64 bug

Hi,

I don't think this is a text/binary issue:
 - I'm already opening with "rb"
 - This is random
 - This only happens when doing concurrent reads
 - ftell works while _ftelli64 has problems

To me this is a race condition in _ftelli64

I have tested the code in MSVC 2015, and the bug is not there.

Etienne

2017-10-19 10:36 GMT+02:00 Kai Tietz via Mingw-w64-public <
[email protected]>:

> Hello,
>
> I am not quite sure if this is a Windows bug.  The API you are using
> is actually that one from msvcrt.dll for large/none-large file
> accesses.
> The most common issue showing this behavior is the TEXT vs. BINARY
> file open mode on Windows C-runtime.  New-lines might be expanded to
> carriage-return + new-line, which can change possitions easily.  To
> avoid that use on file open the additional flag O_BINARY.
>
> Regards, and I hope this will help you,
> Kai
>
> 2017-10-19 10:06 GMT+02:00 Etienne Sandré-Chardonnal <
> [email protected]>:
> > Dear all,
> >
> > I have a program which reads concurrently multiple files using the C I/O
> > library. I have encountered  a problem, _ftelli64 randomly reports an
> > incorrect position, with a mismatch of a few bytes. The bug disappears if
> > any of these changes is done:
> >
> >    - ftell is used instead of _ftelli64 (but no more large file support)
> >    - std::ifstream is used instead of C functions (but I need _wfopen for
> >    unicode file names)
> >    - files are not read concurrently (reading threads set to 1)
> >
> > I have reproduced this in the attached MCVE. It does create 8 files
> > approximately 3MB large, and reads them concurrently in 8 threads by
> 65544
> > byte blocks. It compares the value returned by fread() and the difference
> > between _ftelli64 calls before and after fread(). It prints the
> mismatches.
> >
> > Typical output is :
> >
> > Error 2.dat / ftell before 3080570 / fread returned 65544 / ftell after
> > 3146112 / mismatch -2
> >
> > Error 6.dat / ftell before 3080569 / fread returned 65544 / ftell after
> > 3146112 / mismatch -1
> >
> > Error 4.dat / ftell before 65544 / fread returned 65544 / ftell after
> > 131089 / mismatch 1
> >
> > Error 5.dat / ftell before 0 / fread returned 65544 / ftell after 65543 /
> > mismatch -1
> >
> > Error 5.dat / ftell before 65543 / fread returned 65544 / ftell after
> > 131088 / mismatch 1
> >
> > Error 4.dat / ftell before 2162953 / fread returned 65544 / ftell after
> > 2228498 / mismatch 1
> >
> > Error 5.dat / ftell before 2162952 / fread returned 65544 / ftell after
> > 2228497 / mismatch 1
> >
> > Error 4.dat / ftell before 3080570 / fread returned 65544 / ftell after
> > 3146112 / mismatch -2
> >
> > Error 5.dat / ftell before 3080569 / fread returned 65544 / ftell after
> > 3146112 / mismatch -1
> >
> >
> > Is this a bug from windows or from MinGW C library?
> >
> > Thanks!
> > ------------------------------------------------------------
> ------------------
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > _______________________________________________
> > Mingw-w64-public mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Mingw-w64-public mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to