#2173 _ftelli64 does not return correct value

OTHER
unread
nobody
None
Bug
none
Unknown
False
2014-08-19
2014-01-18
Spacen Jasset
No

_ftelli64 does not return correct value. See code sample. ftelli64 returns 499 instead of 500 like ftell

C:\temp>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/qt/qt5.1.1/tools/mingw48_32/bin/../libexec/gcc/i686-w64-mingw32/4.8.0/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: ../../../src/gcc-4.8.0/configure --host=i686-w64-mingw32 --build=i686-w64-mingw32 --target=i686-w64-mingw32 --pr
fix=/mingw32 --with-sysroot=/temp/x32-480-posix-dwarf-r2/mingw32 --enable-shared --enable-static --disable-multilib --enable-lang
ages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-lto --enable-graphite --enabl
-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-sjlj-exceptions --with-dwarf2 --
isable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-bootstrap --di
able-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=i686
--with-tune=generic --with-host-libstdcxx='-static -lstdc++' --with-libiconv --with-system-zlib --with-gmp=/temp/mingw-prereq/i68
-w64-mingw32-static --with-mpfr=/temp/mingw-prereq/i686-w64-mingw32-static --with-mpc=/temp/mingw-prereq/i686-w64-mingw32-static
-with-isl=/temp/mingw-prereq/i686-w64-mingw32-static --with-cloog=/temp/mingw-prereq/i686-w64-mingw32-static --enable-cloog-backe
d=isl --with-pkgversion='rev2, Built by MinGW-builds project' --with-bugurl=http://sourceforge.net/projects/mingwbuilds/ CFLAGS='
O2 -pipe -I/temp/x32-480-posix-dwarf-r2/libs/include -I/temp/mingw-prereq/x32-zlib/include -I/temp/mingw-prereq/i686-w64-mingw32-
tatic/include' CXXFLAGS='-O2 -pipe -I/temp/x32-480-posix-dwarf-r2/libs/include -I/temp/mingw-prereq/x32-zlib/include -I/temp/ming
-prereq/i686-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/temp/x32-480-posix-dwarf-r2/libs/lib -L/temp/mingw-prereq/x3
-zlib/lib -L/temp/mingw-prereq/i686-w64-mingw32-static/lib -L/temp/x32-480-posix-dwarf-r2/mingw32/opt/lib'
Thread model: posix
gcc version 4.8.0 (rev2, Built by MinGW-builds project)

C:\temp>ld -v
GNU ld (GNU Binutils) 2.23.2

MinGW Compiler suite Bundled with QT5.1.1

#include <assert.h>
#include <stdio.h>

#define SIZE 500

int main()
{
    FILE * i = fopen("test.bin", "w+b");
    char buffer[SIZE]={0};
    size_t n = fwrite(buffer, sizeof buffer[0], SIZE * 2, i); 
    assert(n == SIZE * 2);

    _fseeki64(i, 0, SEEK_SET);
    n = fread(buffer, sizeof buffer[0], SIZE, i);
    printf("fread = %ld\n", n);
    assert(n==SIZE);

    long int pos = ftell(i);
    printf("tell = %ld\n", pos);
    assert(pos == SIZE);

    __int64 pos64 = _ftelli64(i);
    printf("tell64 = %lld\n", pos64);
    assert(pos64 == SIZE); // FAILS

    fclose(i);
}

Windows XP SP3

gcc ftelli64.c -o ftelli64.exe

C:\temp>ftelli64.exe
fread = 500
tell = 500
tell64 = 499
Assertion failed!

Program: C:\temp\ftelli64.exe
File: ftelli64.c, Line 21

Expression: pos64 == SIZE

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Discussion