Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 53
Program Declarations
{
(void) printf ("Error: Must provide input and output "
"file names.\n");
exit (1);
}
/*Open input and output files*/
infile = fopen (argv[1], "r");
outfile = fopen (argv[2], "ab+");
/*Main application processing; read number from input
file and write it to output file and standard output*/
for (;;)
{
/*Return immediately if end of file*/
if (fgets (sp, 10, infile) == NULL) exit (0);
counter = atoi (sp);
printf ("counter = %d\n", counter);
(void) fprintf (outfile, "%d\n", counter);
}
}
The rest of this subsection shows the steps involved in creating an active backup
version of this application.
As in the first example, the program is coded in a modular style, with individual tasks
performed by separate functions. To simplify the presentation, the following conditions
are not handled:
Error conditions returned by C library functions and Guardian procedures are not
handled.
The primary process does not monitor the backup process.
Program Declarations
The particular declarations required by an active backup program depend on the
application. The following are used in this example.
#include and #pragma Lines
The following #include and #pragma lines provide the declarations required by the
program. The conditional statement #ifdef _TNS_R_TARGET causes the lines that
follow it to be included only for native programs, while the lines that are between the
#else line and the #endif line are included only for TNS and accelerated programs.
For native programs, the pragmas ansistreams, runnamed, and
search "$system.system.crtlns" must be included in the compiler command
line.
#ifdef _TNS_R_TARGET
/* for native programs only */