Reputation: 689
How can I get the file size of a file in C when the file size is greater than 4gb?
ftell returns a 4 byte signed long, limiting it to two bytes. stat has a variable of type off_t which is also 4 bytes (not sure of sign), so at most it can tell me the size of a 4gb file.
What if the file is larger than 4 gb?
Upvotes: 4
Views: 2965
Reputation: 9582
try
#define _LARGEFILE64_SOURCE 1
#define _FILE_OFFSET_BITS 64
i think that increases the size of off_t to 64 bits on some operating systems
Upvotes: 1
Reputation: 76541
On Linux with glibc, ftell returns an off_t
; depending on the flags off_t
may be 32 bit or may be 64 bit.
On Linux, you can get the appropriate flags to have a 64 bit off_t
by doing getconf LFS_CFLAGS
(LFS stands for large-file-support).
Upvotes: 2