开发者

How do I get the file size of a large (> 4 GB) file?

How can I get the f开发者_如何学JAVAile 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?


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).


On Windows, GetFileSize[Ex] is what you use.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜