For processing file systems that contain files > 2 gigabytes (GB) a 64-bit variant exists for each of the following 32-bit C Library functions. The 64-bit functions differ from the corresponding 32-bit functions in that they have the suffix “64” in their names.
creat: | creat64 |
fgetpos: | fgetpos64 |
fopen: | fopen64 |
freopen: | freopen64 |
fseek: | fseek64 |
fseeko: | fseeko64 |
fsetpos: | fsetpos64 |
ftell: | ftell64 |
ftello: | ftello64 |
lseek: | lseek64 |
open: | open64 |
tmpfile: | tmpfile64 |
32-bit and 64-bit C/C++ library functions
There is no difference in terms of functionality between the 32-bit variant of a function and the associated 64-bit variant. The only differences concern the data types for parameters and return values if these specify an offset or a file position, since offset and return values > 2 GB must possible in order to process files > 2 GB. Thus, in addition to the 32-bit data type off_t
, for example, there is also a 64-bit data type called off64_t
.
The compilation environment makes available all the explicit 64-bit functions and types in addition to the 32-bit functions and types. A program can thus use either interface, as required.
- The 64-bit functions are only available with ANSI functionality.
- Since most of the names of the 64-bit functions are no longer unique CRTE-wide when truncated to 8 characters, sources that want to use 64-bit functions have to be generated as LLMs.
Using the 64-bit interface
The _FILE_OFFSET_BITS
define allows you to choose between two alternatives for using the 64-bit interface:
using 64-bit functions transparently (
_FILE_OFFSET_BITS 64
)calling 64-bit functions explicitly (
_FILE_OFFSET_BITS 32
)
- The
_FILE_OFFSET_BITS
define must be set on an include file before the first include. - You can replace 32-bit functions with 64-bit functions automatically by means of name defines or macro defines (see section “Preprocessor define_MAP_NAME”).
Using 64-bit functions transparently (_FILE_OFFSET_BITS 64
)
The _FILE_OFFSET_BITS 64
define allows the 64-bit interface to be used transparently, since the 32-bit functions contained in the source code are automatically replaced with the associated 64-bit variants during compilation (with the exception of fseek
and ftell
, see below). In addition, the compilation environment makes data types available in the appropriate size. The data type off_t
, for example, is declared as long long
.
You can use the _MAP_NAME
preprocessor define to specify whether the 32-bit functions are to be mapped to 64-bit functions by means of the name define method or the macro define method (see "Preprocessor define _MAP_NAME").
A program can process both files > 2 GB and files <=
2 GB. Transparent use of the 64-bit functions permits programs that were previously designed only for files <=
2 GB to process files > 2GB without the need for any changes to the source code.
fseek
and ftell
cannot be automatically replaced with fseek64
and ftell64
. Please use the functions fseeko
and ftello
if you want automatic replacement to be carried out.Calling 64-bit functions explicitly
If the _FILE_OFFSET_BITS 32
define is set or if _FILE_OFFSET_BITS
is not defined, you have to use the 64-bit variants of the file processing functions described above in order to process files > 2 GB:
If you try to process a file > 2 GB using a 32-bit variant, this leads to abortion.
If you use the 64-bit variants, however, you can also process files
<=
2 GB.
_LARGEFILE64_SOURCE 1
define is set beforehand (prototype generation and further defines).