跨平台寻求大文件

时间:2013-06-19 11:05:17

标签: c cross-platform seek fseek

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

0 个答案:

没有答案