Off_t without -D_FILE_OFFSET_BITS = 64 in file> 2GB

1- I am wondering what the problem is if I try to read a file larger than 2GB in size without compiling my program using the -D_FILE_OFFSET_BITS=64 option using off_t and using the second function on this page ? will it be segfault?

2- I plan to use this implementation using off64_t and

 #define _LARGEFILE64_SOURCE 1 #define _FILE_OFFSET_BITS 64 

Will there be a problem?

+4
source share
3 answers
  • stat () will fail, and errno set to EOVERFLOW in this case. Here is what the linux man page says

     EOVERFLOW stat()) path refers to a file whose size cannot be represented in the type off_t. This can occur when an application 

    compiled on a 32-bit platform without -D_FILE_OFFSET_BITS = 64 calls stat () on a file whose size exceeds (2 <31) -1 bits.

  • If you compile with -D_FILE_OFFSET_BITS = 64, you do not need to use off64_t. You can just continue to use off_t, it will become 64-bit, and all functions working with files and file sizes will become 64-bit.
+8
source

Never use off64_t explicitly. Always create your programs with 64-bit file offsets on systems where you need to explicitly specify this. Failure to do so is a major mistake that your users will hate. I do not know why this is not a default on modern systems ...

+1
source

This is not segfault, but the file size will be reported incorrectly.

-1
source

Source: https://habr.com/ru/post/1315301/


All Articles