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

Table Of Contents
Interfacing to Guardian Procedures and OSS
Functions
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
3-5
Procedures That Return a Condition Code
Example 3-2. 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);