简体   繁体   中英

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). But if I do like below the value of the result is -1 which is not success. 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.

Check out fseeko (which takes a 64bit number).

You need to use the 64-bit version of fseek() :

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

And for lseek() :

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

There's also lseek64() , but as mentioned by @R.. (see comments), it should not be used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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