Open System Services Programmer's Guide
Example 21 Reading an OSS File in Nowait Mode With Guardian Procedures
/* Reading an OSS file in Nowait Mode with Guardian Procedures */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <tal.h>
#include <cextdecs.h(FILE_OPEN_,READX,AWAITIOX)>
_cc_status CC;
short filenum, bytesread, retcode;
char *pathname;
char buffer[1025]; /* allow for NULL character at end of buffer */
long request_tag;
int i;
int main(int argc, char *argv[]) {
/* Check for the proper number of arguments;
if no pathname is supplied, use the default name. */
if (argc > 1)
pathname = argv[1];
else
pathname = "/usr/include/stdio.h";
/* Invoke the Guardian procedure. Note the value of "options" field. */
retcode = FILE_OPEN_(pathname, /* name of OSS file */
, /* pathname length not needed */
&filenum, /* file number returned */
1, /* open for read */
, /* shared exclusion */
1, /* number of concurrent nowait I/O
operations permitted */
, /* sync or receive depth */
040, /* <10>=1 indicates OSS pathname */
);
/* If the open is unsuccessful, print a message and exit. */
if (retcode != 0) {
fprintf(stderr, "retcode = %d\n", retcode);
fprintf(stderr, "Cannot open %s\n", pathname);
exit(1);
}
/* Read the file using the Guardian READX procedure.
Note that a request tag is not required when only one
outstanding read is issued. It is shown here for
demonstration purposes only. */
request_tag = 123; /* form unique request tag */
CC = READX( filenum, /* file number */
buffer, /* buffer address */
1024, /* size of buffer */
, /* number of bytes read, not
used for nowait I/O */
request_tag /* unique request tag */
);
/* If the condition code returned is not the one for success,
print a message and exit. */
if(_status_ne(CC)) { /* check the success condition code */
printf(stderr, "Read failed\n");
exit(1);
}
Accessing Files From the Guardian API 71










