TNS/E Native Application Conversion Guide

C and C++ Conversion Tasks
TNS/E Native Application Conversion Guide529659-003
3-13
Changing Programs That Use Guardian and OSS
Environment Interoperability
Changing Programs That Use Guardian and
OSS Environment Interoperability
Because of differences in the Guardian and OSS file systems, six functions require
environment-specific parameters: fopen(), freopen(), remove(), rename(),
tmpnam(), and tmpfile(). Each of these base functions has a Guardian variant and
an OSS variant, such as fopen_guardian() and fopen_oss().
In TNS programs, the environment-specific parameters expected by these base
functions are determined at compile time. That is, the functions expect Guardian
parameters if called from a module compiled with SYSTYPE GUARDIAN and expect
OSS parameters if called from a module compiled with SYSTYPE OSS. The run-time
environment of the process the module is bound into does not affect the call. For
example, an fopen() call in a module compiled with SYSTYPE GUARDIAN and
bound into a program that runs as an OSS process expects a Guardian parameter at
run time.
In native programs, the environment-specific parameters expected by these base
functions are determined at run time. That is, the functions expect Guardian
parameters if called from a Guardian process and OSS parameters if called from an
OSS process. The compilation environment is ignored. This change was made to
simplify and enhance the usability of the Guardian and OSS environment
interoperability model.
In modules compiled with SYSTYPE OSS and linked into a program that runs as a
Guardian process, replace calls to the base function with calls to the _oss variant.
Likewise, in modules compiled with SYSTYPE GUARDIAN and linked into a program
that runs as an OSS process, replace calls to the base function with calls to the
_guardian variant. For example, replace calls to fopen() with either fopen_oss()
or fopen_guardian(), as appropriate.
Changing Code That Relies on Arithmetic
Overflow Traps
Guardian TNS C library functions, such as the tan() function, generate a trap on
arithmetic overflow. In the Guardian native C library, such functions generate neither a
trap nor a signal on arithmetic overflow. In most cases, the functions set errno to
[ERANGE] or [EDOM] to indicate arithmetic overflow. The behavior of Guardian native
C library functions now matches the behavior of the TNS and native OSS C library
functions. Change your code that relies on arithmetic overflow to evaluate either
errno or the parameters to the function call.
By default, the native C and C++ compilers do not generate code that traps on
arithmetic overflow. Specify an OVERFLOW_TRAPS pragma to generate code that traps
(raises a signal) on arithmetic overflow. The overflow traps occur in code generated by
the compiler, not code linked into the program (for example, C library functions).