Open System Services Programmer's Guide
Example 2 Calling a Guardian Procedure That Returns a Return Value
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cextdecs.h(FILE_GETINFOBYNAME_)> /* Note 1 */
char *filename;
short typeinfo[5];
int main(int argc, char *argv[]) {
 short retcode, physreclen; /* Note 2 */
/* 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 3 */
 , /* 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 cextdecs.h library header file contains function prototype declarations for Guardian
procedures you can call directly from a C program. It is important to specify which Guardian
procedures the program will call; otherwise, all function prototype declarations in cextdecs.h
are included in your program. In this program, only the function prototype declaration for the
FILE_GETINFOBYNAME_ procedure is included.
To use cextdecs.h with a native program, you must specify the EXTENSIONS pragma,
because the procedure declarations in cextdecs.h use _tal syntax instead of the pragma
function syntax.
Note 2
The integer into which a value is returned, retcode, is declared as a short integer. This is
because the integer data type in Guardian procedures represents a 16-bit word, while the
integer data type in OSS C programs represents a 32-bit word.
Calling Functions and Procedures in OSS Programs 39










