Open System Services Porting Guide (G06.29+, H06.06+, J06.03+)
Advantages to choosing the transitional compilation environment include:
• Clean up of code can be confined to the routines that handle large files.
• Because the 64-bit APIs can use different data types and structures than the 32-bit versions,
calling the 64-bit APIs explicitly can result in code that is easier to debug.
• If handling large files is the exception, you might not have to examine or change as much of
the application code.
The 64-bit APIs provided by HP and listed in the Open System Services Programmer’s Guide are
large file aware. However, these are extension functions and calling them explicitly in your
application limits the future portability of the application, which can be a disadvantage to choosing
the transitional compilation environment.
Choosing the Large File Compilation Environment
Another way to enable large file support is to use the large file compilation environment.A module
is considered to be compiled in a large file compilation environment when you use the #define
_FILE_OFFSET_BITS 64 feature test macro or an equivalent compiler command option to
compile the application. When you use the large file compilation environment, an application call
to interface() is automatically mapped to the interface64() function.
The advantage of the using the large file compilation environment is portability. The disadvantage
is that you can run into problems mixing objects from the regular and the large file compilation
environments.
Suppose one of the source files contains a routine that passes an off_t, or a struct stat, or
anything else with a size that is affected by the compile environment, to a routine in another file
compiled in the other environment. This code will not work, and it can be difficult to determine
why, because the source code does not appear to have errors.
The problem can also exist between objects and a library that you use, possibly supplied by some
other company. If the library interface contains an off_t (or any other data type whose size is
different in each compilation environment) then using the large file compilation environment might
not work correctly if the library was compiled in a regular compilation environment.
Because of these mixing issues, HP recommends using the large file compilation environment only
when every object file can be compiled in the large file compilation environment. You can mix
objects if you ensure that no data whose type is different in the two environments is passed between
the two environments (or referenced as global data), but this design is not recommended.
NOTE: The linker cannot prevent objects from being mixed in the same executable file because
the object is not in any way marked as being from one environment or the other.
General Conversion Issues
In many programs, assumptions are made that integers, long integers, pointers, and offsets are all
the same size. This leads to programming practices that are not conducive to converting to large
files. Every program that makes the above assumptions will need to be modified to support large
files. Typical problems include:
• Offsets are assigned to an int or a long data type.
• Offsets are passed to routines whose parameters are either undeclared or declared as the
wrong type.
• Constants are passed as offsets without casting in non-ANSI mode. For example, in this existing
code fragment, 0 is not cast:
lseek(fd, 0, SEEK_SET);
In the large file compilation environment, 0 must be type off64_t, because lseek() is
mapped to lseek64(). In the transitional compilation environment, 0 must be of type off_t.
192 Porting Applications to Support Large OSS Files