Menu

#864 _ftelli64 returns wrong values with MinGW-w64 32-bit

v1.0 (example)
open
nobody
5
2022-06-05
2020-11-11
No

A very good day to You,
I stumbled upon a little problem when trying to read binary data from a file with a program compiled using the MinGW-w64 32-bit compiler (the one currently distributed with Qt - build-info is attached as a separate file) running under a Windows 10 64-bit system.
An MWI is attached as well - it first creates a file with meaningless data and then tries to read part of it back. The part to read is 2 times 4 bytes, i.e. 8 bytes total. Querying _ftelli64() afterwards however returns only "7" for me if the file stream is buffered (the default).
The MinGW-w64 64-bit compiler returns "8" (as does a current MSVC). For an unbuffered stream MinGW-w64 32-bit also returns "8".
Am I doing something wrong? Did I overlook something in the documentation which should prevent me from using _ftelli64() in this fashion? Or might this be a problem of Microsoft Windows 10 in relation with the MinGW-w64 32-bit compiler?
Feedback would be very much appreciated,
J. Wilde

2 Attachments

Discussion

  • Johannes Wilde

    Johannes Wilde - 2020-11-11

    I should probably add that ftello64 returns "8" for all tested compilers.

     
  • David Bryant

    David Bryant - 2022-06-05

    Hi. I am seeing this exact same bug. It occurs only with the 32-bit compiler (the 64-bit compiler is fine) and the executables fail exactly the same way whether they are run on Wine or an XP VM (which I assume means they'll fail anywhere they will run). I grabbed the MS demo of ftell() and modified it to demonstrate with just a few lines:

    $ i686-w64-mingw32-gcc --version
    i686-w64-mingw32-gcc (GCC) 9.3-win32 20200320
    Copyright (C) 2019 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
    $ cat crt_ftell.c
    // crt_ftell.c
    // This program opens a file named CRT_FTELL.C
    // for reading and tries to read 100 characters. It
    // then uses ftell to determine the position of the
    // file pointer and displays this position.
    
    #include <stdio.h>
    
    FILE *stream;
    
    int main( void )
    {
       char list[100];
       if( (stream = fopen( "crt_ftell.c", "rb" )) != NULL )
       {
          // Move the pointer by reading data:
          fread( list, sizeof( char ), 100, stream );
          // Get position after read:
          printf( "Position after trying to read 100 bytes: %ld\n", ftell (stream));
          printf( "Position after trying to read 100 bytes: %I64d\n", _ftelli64 (stream));
          printf( "Position after trying to read 100 bytes: %I64d\n", ftello64 (stream));
          fclose( stream );
       }
    }
    $ i686-w64-mingw32-gcc -Wall crt_ftell.c -o crt_ftell.exe
    $ wine ./crt_ftell.exe 
    Position after trying to read 100 bytes: 100
    Position after trying to read 100 bytes: 78
    Position after trying to read 100 bytes: 100
    $ 
    

    Cheers!

     

Log in to post a comment.

MongoDB Logo MongoDB