大型文件是否存在跨平台fseek()
?超过2GB
限制时寻求失败。
size_t chunkSkip = 1024 * 4;
uint64_t skipped = 0;
while (skipped < args.nSkipBytes) {
uint64_t offset;
if (skipped + chunkSkip > args.nSkipBytes) {
offset = args.nSkipBytes - skipped;
}
else {
offset = chunkSkip;
}
int res = fseek(fp, offset, SEEK_CUR);
if (res != 0) {
fprintf(stderr, "Could not skip %llu bytes, file may be "
"too small. Result: %d\n", args.nSkipBytes, res);
charbuffer_free(printable);
charbuffer_free(unprintable);
return ECANCELED;
}
skipped += offset;
}
我读过_fseeki64()
,但这似乎只是MSVC?如果没有,我会对GCC解决方案更感兴趣。