c++cfseekfgetpos

Determining the size of a file larger than 4GB


The code currently does this and the fgetpos does handle files larger than 4GB but the seek returns an error, so any idea how to seek to the end of a file > 4GB?

fpos_t currentpos;

sok=fseek(fp,0,SEEK_END);
assert(sok==0,"Seek error!");

fgetpos(fp,&currentpos);
m_filesize=currentpos;

Solution

  • If you're in Windows, you want GetFileSizeEx (MSDN). The return value is a 64bit int.

    On linux stat64 (manpage) is correct. fstat if you're working with a FILE*.