The KcsFile class is a file I/O derivative of the KcsIO class. It provides a way to manipulate files by creating a KcsIO object. You can use the protected and public member functions in this class in the implementation of your CMM; you cannot override any member function in this class.
The header file for the class is kcsfile.h.
It is highly recommended that you do not use any of the variables and functions for handle-based memory in the kcsmblk.h header file. Handle-based memory is not required on the Solaris system.
The constant and #define identifiers of this class as defined in the kcsids.h header file are:
const KcsId KcsIOFileId = {(0x46696C65UL)}; /* 'File' */ #define KcsIOFileIdd (0x46696C65UL) /* 'File' */
In addition to the KcsIO virtual functions that must be overridden for a minimal KcsIO implementation, the KcsFile class has member functions for reading from and writing to a file. See Table 2-4 for detailed information on the virtual functions that are minimally required to derive from the KcsIO class.
This class does not have any protected members; the public members are described.
The KcsFile class provides the following public members.
Table 2-8 KcsFile Public Members
The following examples show you how to use the KcsFile class.
This example shows you how to read a file from a specified offset with absRead(). See the kcsio.h header file for a description of absRead().
KcsStatus readIt() { KcsStatus sStatus; KcsFileId sFileRef; long index = 32; long number; // open the file, put the fileRef into sFileRef sFileRef = open ("Profile", O_RDWR); if (sFileRef == -1) return (KCS_IO_ERROR); // create a file object file = new KcsFile(&sStatus, sFileRef, 0); if (sStatus != KCS_SUCCESS) return(sStatus); // using the file object, read from the file into a buffer. sStatus = file->absRead(index, sizeof(long), &number); delete file; close(sFileRef); return (sStatus); } |
This example shows you how to write to a file with relWrite(). See Table 2-3 for a full definition of relWrite().
KcsStatus writeIt() { KcsStatus sStatus; KcsFileId sFileRef; long nbytes; char *buffer; // open the file, get a fileRef sFileRef = open ("Profile", O_RDWR); if (sFileRef == -1) return (KCS_IO_ERROR); // create a file object file = new KcsFile(&sStatus, sFileRef); if (sStatus != KCS_SUCCESS) return(sStatus); // Allocate memory for the buffer, fill it with data. // Set nbytes to the length of the buffer. if ((buffer = (char*) malloc(nbytes)) == NULL) return (KCS_IO_ERROR); delete file; close(sFileRef); // using the file object, write the buffer to the file. sStatus = file->relWrite(nbytes, buffer); // Free the buffer's memory. free (buffer); delete file; close(sFileRef); return (sStatus); } |