Generic header files using ILE APIs

See Code disclaimer information for information pertaining to code examples.

This section shows how to use a generic header file from the QSYSINC (system include) library in a program. For information about the QSYSINC header files, see Include files and the QSYSINC library.

In addition to the traditional C-library header files (such as stdio and string), the API header file qusrgfa1.h is included in the following example. The qusrgfa1.h header file defines the functions exported from service program QUSRGFA1. This service program contains the APIs provided for manipulating the information in the repository. A second service program named QUSRGFA2 contains the ILE API for retrieving information from the registration facility repository. The header file qusec.h contains the definition for the error code structure that is used for the error code parameter. The following list shows the standard C header files (the first four includes) and a few &sys.-defined header files for APIs. This list does not show all the header files used in the example programs for using ILE APIs.

           #include <stdio.h>
           #include <signal.h>
           #include <string.h>
           #include <stdlib.h>
           #include <qusrgfa1.h>
           #include <qusec.h>

Example: Variable-length structure

Many of the structures needed are provided by the QSYSINC (system include) library. However, any fields of a structure that are variable in length are not defined by QSYSINC and must be defined by the user. For example, in the qusec.h header file, the structure Qus_EC_t is defined as:

           typedef struct Qus_EC {
                int  Bytes_Provided;
                int  Bytes_Available;
                char Exception_Id[7];
                char Reserved;
              /*char Exception_Data[]; (1)*/   /* Varying length field  */
           } Qus_EC_t;

Because the Exception_Data field (1) is a varying-length field, it is shown as a comment. The following is a new error code structure, which defines the exception_data field (2). It was created by using the structure that was defined in the qusec.h header file.

           typedef struct {
                Qus_EC_t ec_fields;
                char     exception_data[100](2);
           } error_code_struct;

Within QSYSINC include files, all varying-length fields and arrays are in the form of comments so that you can control how much storage to allocate based on your specific requirements.

End of change