将大于long类型的最大值的值传递给C中的fseek

Pass a value greater than maximum value of long type to fseek in C

本文关键字:中的 fseek 最大值 大于 long 类型 值传      更新时间:2023-10-16

我需要将一些值传递给C中的fseek()方法,这些值大于有符号长类型的最大值(2147483647)。但如果我真的喜欢下面的值,结果是-1,那就不是成功。有没有我能做到这一点?

//fp is the pointer to fopen method
unsigned long long index=2147483648;
int status = fseek(fp, index, SEEK_SET);

既然你用"Objective-C"标记了它,我想你也在考虑Macintosh。

查看fseeko(采用64位数字)。

您需要使用64位版本的fseek():

  • Windows:_fseeki64()
  • Linux:fseeko()#define _FILE_OFFSET_BITS 64-D_FILE_OFFSET_BITS=64

对于lseek():

  • Windows:_lseeki64()
  • Linux:lseek()#define _FILE_OFFSET_BITS 64-D_FILE_OFFSET_BITS=64

还有lseek64(),但正如@R所提到的。。(见评论),不应使用。