0

是否有大文件的跨平台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 解决方案更感兴趣。

4

0 回答 0