[英]File size of a >4gb file?
In MSVC I ran the following code. 在MSVC中,我运行了以下代码。 a gives me -1, b gives me EINVAL and c gives me 0. When the path is a file that can fit in a 32bit value this function works fine.
a给我-1,b给我EINVAL,c给我0。当路径是可以容纳32位值的文件时,此功能可以正常工作。 How do I get the length of a file >4gb?
如何获取文件长度> 4GB?
f = fopen(path.c_str(), "r+b");
printf("f=%X\n", f);
auto a = fseek(f, 0, SEEK_END);
auto b = errno;
auto c = ftell(f);
MSVC has 64 bit variants of most C stdlib file functions which allow you to work with files larger that 4GB, in your case, see _ftelli64
. MSVC具有大多数C stdlib文件功能的64位变体,使您可以处理大于4GB的文件,具体情况请参见
_ftelli64
。 There is also _filelengthi64
for descriptors (which you can get using _fileno
). 还有用于描述符的
_filelengthi64
(您可以使用_fileno
获得)。
The POSIX API uses lseek
which takes a off_t
argument. POSIX API使用带有
off_t
参数的lseek
。
Windows API uses SetFilePointerEx
which takes a LARGE_INTEGER
argument. Windows API的使用
SetFilePointerEx
这需要一个LARGE_INTEGER
的说法。
And @Necrolis told you the clib MSVC extension... @Necrolis告诉您clib MSVC扩展...
boost::file_size
returns the largest available integer type, so at least 64 bits. boost::file_size
返回最大的可用整数类型,因此至少为 64位。 Works on all major platforms. 适用于所有主要平台。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.