Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining the size of a file larger than 4GB

Tags:

c++

c

fseek

fgetpos

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;
like image 931
KPexEA Avatar asked Sep 22 '08 02:09

KPexEA


1 Answers

Ignore all the answers with "64" appearing in them. On Linux, you should add -D_FILE_OFFSET_BITS=64 to your CFLAGS and use the fseeko and ftello functions which take/return off_t values instead of long. These are not part of C but POSIX. Other (non-Linux) POSIX systems may need different options to ensure that off_t is 64-bit; check your documentation.

like image 131
R.. GitHub STOP HELPING ICE Avatar answered Sep 20 '22 07:09

R.. GitHub STOP HELPING ICE