Open System Services Programmer's Guide

Example 24 Using a Guardian Procedure to Get OSS File Information by Number
/* Using a Guardian Procedure to Get OSS File info by Number*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cextdecs.h(FILE_OPEN_,FILE_GETINFO_)>
short typeinfo[5];
char filename[64];
char *pathname;
int main(int argc, char *argv[]) {
short filenum, filelen, retcode, lasterror;
/* If no pathname is supplied, open the default file. */
if(argc > 1)
pathname = argv[1];
else
pathname = "/usr/include/stdio.h";
retcode = FILE_OPEN_(pathname, /* OSS pathname */
, /* pathname length not required */
&filenum, /* returned file number */
1, /* read-only access */
, /* shared exclusion */
, /* nowait depth */
, /* sync or receive depth */
040, /* <10>=1, set to OSS pathname */
);
/* If the FILE_OPEN_ procedure is unsuccessful,
print a message and exit. */
if (retcode != 0) {
fprintf(stderr, "retcode = %d, filenum = %d\n",
retcode, filenum);
fprintf(stderr, "Cannot open %s\n", pathname);
exit(1);
}
/* Get information about the file by file number. */
retcode = FILE_GETINFO_(filenum, /* file number */
&lasterror, /* error from last operation */
filename, /* Guardian filename returned */
64, /* length of filename buffer */
&filelen, /* number of bytes in filename */
typeinfo ); /* return array of file information */
/* If the procedure is unsuccessful, print a message and exit.*/
if (retcode != 0) {
fprintf(stderr, "retcode = %d, filenum = %d\n",
retcode, filenum);
fprintf(stderr, "Non-existent file or filename in bad format\n");
exit(1);
}
/* Print the file status information. */
printf("Pathname = %s\n", pathname);
filename[filelen] = '\000'; /* make string NULL-terminated */
printf("Filename = %s\n", filename);
printf("device subtype = %d\n", typeinfo[1]);
printf("device type = %d\n", typeinfo[0]);
/* If the device type is a disk file,
print the disk file information. */
Accessing Files From the Guardian API 77