C/C++ Programmer's Guide (G06.27+, H06.08+, J06.03+)

Example 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) { /* its 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);
}
Procedures That Return a Condition Code
Example 2: Calling a Guardian Procedure That Returns a Condition Code 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.
The tal.h library header file must be included when you call Guardian procedures that
return condition codes.
Note 1
The _cc_status type specifier indicates that a procedure does not return a value but
does set a condition code.
Note 2
68 Interfacing to Guardian Procedures and OSS Functions