How to access files larger than 2GB in your program on Linux/x86

Background

X86 is a 32-bit platform. Therefore, the files size on a Linux/x86 system is usually limited to 2GB. But now we can access files larger than 2GB through Large File Support (LFS). To use LFS in your program, you will need to know three macros: You have two ways to define the macros:

Prerequisite

Program

To access file larger than 2GB, you can use LFS in two ways: In either way, the data type must be consistent with LFS. For example, you must use off_t (for case 2), off64_t (for case 1), or long long to store the offset. If you want to print it, use printf("%lld", offset);
Functions which do not deal with offset directly such as fread(), fgetc() do not have a 64-bit counterpart. They are still used in LFS (thanks to Rizwen Butt).

References


Valid HTML 4.01! GoStats says you are visitor number