Open System Services Programmer's Guide

Example 18 Using FILE_COMPLETE_SET_, FILE_COMPLETE_, and FILE_COMPLETE_GETINFO_
/* Guardian FILE_COMPLETE_* procedures */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tdmext.h>
#include <unistd.h>
#include <fcntl.h>
#include <zsysc>.h>
#include <tal.h>
#include <cextdecs.hh(FILE_OPEN_,READX,FILE_COMPLETE_,AWAITIOX,\
FILE_COMPLETE_SET_,FILE_COMPLETE_GETINFO_)>
_cc_status CC;
short filenum, fnum, bytesread;
int fd,nb;
short retcode, status;
char *pathname; /* OSS path name */
char *filename; /* Guardian file name */
char bufoss[1025]; /* allow for NULL character at end of OSS buffer */
char bufgdn[1025]; /* allow for NULL character at end of Guardian buffer */
zsys_ddl_complete_element_def comp_elem[2]; /* completion elements */
short err_elem; /* error return for FILE_COMPLETE_SET_ */
short num_elem; /* Total number of Guardian and OSS files */
zsys_ddl_completion_info_def comp_info; /* completion information */
zsys_ddl_complete_element_def info_list[7];
/* array of information elements */
char buffer[1026]; /* allow for NULL termination of string in buffer */
long request_tag;
int i;
int main(int argc, char *argv[]) {
/* Check for the proper number of arguments;
if no path/file names are supplied, use the default names. */
if (argc > 1)
pathname = argv[1];
else
pathname = "/usr/include/stdio.h";
if(argc > 2)
filename = argv[2];
else
filename = "$system.system.stdioh";
/* Open the OSS file in non-blocking and read-only mode */
fd = open(pathname, O_NONBLOCK|O_RDONLY);
/* If the open is unsuccessful, print a message and exit. */
if (fd < 0) {
fprintf(stderr, "Cannot open %s\n", pathname);
exit(1);
}
/* Open the Guardian file in nowait mode */
retcode = FILE_OPEN_(filename, /* name of Guardian file */
(short) strlen(filename), /* filename length */
&filenum, /* file number returned */
1, /* open for read */
, /* shared exclusion */
1, /* number of concurrent nowait I/O
operations permitted */
, /* sync or receive depth */
, /* Guardian filename */
);
/* If the open is unsuccessful, print a message and exit. */
if (retcode != 0) {
fprintf(stderr, "Cannot open %s\n", filename);
fprintf(stderr, "retcode = %d\n", retcode);
exit(1);
}
60 Managing Files