The initialization user function

You may need a user function to perform program initialization tasks, for example when you need to initialize a link to a host computer. When defining a custom server, you can specify the name of an initialization user function only for system-generated main() functions. This function is linked with your other user functions and the main() function in the build process.

The custom server main() arguments argc (parameter count) and argv (a pointer to a list of parameters) are passed to the initialization user function. The initialization function accepts only these parameters and must return void as in the example below. The initialization user function is called automatically when the custom server is started, immediately following the CA_Init() subroutine. If you code the main() function yourself, code it in this way.

The following shows an example of an initialization user function:

extern FILE *file1_fp; 
extern FILE *file2_fp;

void open_files(int argc, char *argv[])
{
   char fname1[100];
   char fname2[100];

   if (argc == 3) {
        strcpy(fname1,argv[1]);
        strcpy(fname2,argv[2]);
   } else {
        strcpy(fname1,"default1.dat");
        strcpy(fname2,"default2.dat");
   }
   if ((file1_fp = fopen(fname1,"w+")) == NULL) {
      CA_Terminate(0);
   }
   if ((file2_fp = fopen(fname2,"w+")) == NULL) {
      CA_Terminate(0);
   }
}   

When attaching to shared memory (for example, by using the AIX system call shmat()), you should never specify a specific address for the attach; always allow the system to select the address. Failure to do so may cause calls to the custom server API to fail.

To define an initialization user function, see Defining the main() function.