Open System Services Programmer's Guide
Example 3 Calling a Guardian Procedure That Returns a Condition Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tal.h> /* Note 1 */
#include <cextdecs.h(FILE_OPEN_,READX)>
_cc_status CC; /* Note 2 */
short filenum, bytesread, retcode;
char *filename;
char buffer[1024];
int main(int argc, char *argv[]) {
int i;
/* Get Guardian filename and open the file. */
if (argc > 1)
filename = argv[1];
else
filename = "$system.system.stdioh";
retcode = FILE_OPEN_(filename, /* name of Guardian file*/
(short)strlen(filename), /* filename length */
&filenum, /* file number returned */
1, /* open for read */
, /* exclusion */
, /* nowait depth */
, /* sync or receive depth */
);
/* Check if open was successful. */
if (retcode != 0) {
fprintf(stderr, "retcode = %d\n", retcode);
fprintf(stderr, "Can't open %s\n", filename);
exit(1);
}
/* Read from the file and check for valid condition code. */
CC = READX( filenum, /* file number */
buffer, /* buffer address */
1024, /* size of buffer */
&bytesread, /* number of bytes read */
);
if(_status_ne(CC)) { /* if condition code indicates an error */
fprintf(stderr, "Read error, bytes read = %d\n", bytesread);
exit(1);
}
/* Print number of bytes read and contents of first ten bytes.*/
printf("Bytes read = %d\n", bytesread);
printf("First 10 bytes read (in octal): ");
for (i = 0; i < 10; i++)
printf("%o ", buffer[i]);
printf("\n");
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 _catalysts type-specifier indicates that a procedure does not return a value but does
set a condition code.
Calling Functions and Procedures in OSS Programs 41