简体   繁体   English

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

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

I need to pass some values to the fseek() method in C which are greater than the maximum value of the signed long type (2147483647). 我需要将一些值传递给C中的fseek()方法,该方法大于signed long类型的最大值(2147483647)。 But if I do like below the value of the result is -1 which is not success. 但如果我喜欢下面结果的值是-1,这是不成功的。 Is there anyway that I can do this? 无论如何我能做到这一点吗?

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

Since you tagged this with "Objective-C", I'm assuming you are also thinking about Macintosh. 既然你用“Objective-C”标记了这个,我假设你也在考虑使用Macintosh。

Check out fseeko (which takes a 64bit number). 查看fseeko (需要64位数字)。

You need to use the 64-bit version of fseek() : 您需要使用64位版本的fseek()

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

And for lseek() : 对于lseek()

  • Windows: _lseeki64() Windows: _lseeki64()
  • Linux: lseek() with #define _FILE_OFFSET_BITS 64 or -D_FILE_OFFSET_BITS=64 Linux: lseek()使用#define _FILE_OFFSET_BITS 64-D_FILE_OFFSET_BITS=64

There's also lseek64() , but as mentioned by @R.. (see comments), it should not be used. 还有lseek64() ,但正如@R所提到的那样(见注释),不应该使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM