Reputation:
In MSVC I ran the following code. 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. How do I get the length of a file >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);
Upvotes: 1
Views: 556
Reputation: 179907
boost::file_size
returns the largest available integer type, so at least 64 bits. Works on all major platforms.
Upvotes: 0
Reputation: 294297
The POSIX API uses lseek
which takes a off_t
argument.
Windows API uses SetFilePointerEx
which takes a LARGE_INTEGER
argument.
And @Necrolis told you the clib MSVC extension...
Upvotes: 2
Reputation: 26171
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
. There is also _filelengthi64
for descriptors (which you can get using _fileno
).
Upvotes: 3