C/C++ Programmer's Guide (G06.25+)
Interfacing to Guardian Procedures and OSS
Functions
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
3-4
Procedures That Return a Condition Code
Procedures That Return a Condition Code
Example 3-2 on page 3-5 calls the Guardian procedures FILE_OPEN_ and READX to
open and read data from a Guardian file, which is provided as an input parameter to
the procedure. FILE_OPEN_ returns a return value in retcode, and READX returns a
condition code in CC.
Example 3-1. Calling a Guardian Procedure That Returns a Return Value
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cextdecs.h(FILE_GETINFOBYNAME_)>
char *filename;
short typeinfo[5];
int main(int argc, char *argv[]) {
short retcode, physreclen; /* Note 1 */
/* Get Guardian filename and pass it to the Guardian procedure. */
if(argc > 1)
filename = argv[1];
else
filename = "$system.system.stdioh";
retcode = FILE_GETINFOBYNAME_(filename, /* Guardian filename */
(short) strlen(filename), /* filename length */
typeinfo, /* return array of file information */
&physreclen, /* returned physical record length */
, /* desired options, if any Note 2 */
, /* tag or timeout value, if any */
);
/* Check for valid filename. */
if (retcode != 0) {
fprintf(stderr, "retcode = %d\n", retcode);
fprintf(stderr, "Non-existent file or filename in bad format\n");
exit(1);
}
/* Print information for a disk file. */
printf("Filename = %s\n", filename);
printf("device type = %d\n", typeinfo[0]);
printf("device subtype = %d\n", typeinfo[1]);
printf("physical record length = %d\n", physreclen);
if(typeinfo[0] == 3) { /* it’s a disk file */
printf("object type = %d\n", typeinfo[2]);
printf("file type = %d\n", typeinfo[3]);
printf("file code = %d\n", typeinfo[4]);
}
return(0);
}
Note 1 The tal.h library header file must be included when you call Guardian
procedures that return condition codes.
Note 2 The _cc_status type specifier indicates that a procedure does not
return a value but does set a condition code.