Open System Services Porting Guide (G06.29+, H06.06+, J06.03+)
• “HP Extensions” (page 110)
• “Programming for Portability” (page 110)
Scope of Portability
Scope of portability refers to the number of target platforms on which the program currently runs
or will run. To ensure that the program stays portable to the UNIX environment from which you
are porting, you must make sure that you do not use extensions specific to HP, if possible. If the
UNIX program uses only standard POSIX and ISO/ANSI C functions, keeping the program portable
will be easier. You should make the decision about the scope of portability of your program first,
before you take the actual steps of porting the source code to the OSS environment.
If the program already uses vendor-specific extensions, place these extensions in separately
compilable modules or include them in #ifdef directives. If you use some HP extensions to take
advantage of the OSS environment, place the extensions in a separate module to keep the program
portable. If you make significant changes to the program to take advantage of the OSS environment
and do not plan to keep the program portable to the UNIX environment from which it was ported,
you have more flexibility in rewriting parts of the program. You should still, however, put extensions
in separate source modules or within #ifdef directives, whenever possible.
Levels of Portability
There are three levels of portability to consider when porting a program from a UNIX environment
to the OSS environment: compiler, data-file, and operating environment.
Portability Through Compiler Compatibility
Compiler compatibility exists when any operating-system-independent portions of C code have
identical execution semantics on different systems. C compilers fulfilling the ISO/ANSI C specification
are usually sufficiently compatible. (Most porting difficulties occur because of underlying hardware
differences when the C compilers on the two systems are compatible.) Porting programs written in
Common C to the OSS environment is discussed in “OSS C Programming Considerations”
(page 115).
Portability Through Data-File Compatibility
Data-file compatibility exists when binary data images corresponding to any C structure or data
type can be exchanged between systems. Such compatibility requires that data type sizes, structure
padding conventions, byte orders within multibyte data, and floating-point representations all be
compatible among the systems involved. Compatibility can be achieved between systems using
similar processors and standard transport media formats, but is rarely achieved between two
dissimilar hardware architectures (except with much care).
Portability Through Operating Environment Compatibility
Operating environment compatibility exists when two operating systems support or can emulate a
sufficiently complete mutual subset of operating system and support function calls. This compatibility
includes features necessary for developing target applications, but may not include facilities that
are hardware-independent in principle or that are used only for system maintenance. Strong
operating system compatibility exist among most vendors’ UNIX systems: most are compatible with
the XPG4 specifications.
Porting Analysis
One of the first things you should do before starting a porting task is determine the level of effort
necessary to perform the port. The ease of the porting task depends largely on the compatibility
between the C compilers and the operating system interfaces used in the two environments. By
108 Porting UNIX Applications to the OSS Environment