KCMS CMM Reference Manual

Example

The following code shows you some examples of how to use these KcsChunkSet class member functions: getChunkSet(), getChunkSize(), readChunk(), and writeChunk().


Example 3-1 Getting, Reading and Writing a Chunk

KcsChunkId				myChunkId;
 KcsStatus				aStat;
 KcsChunkSet*				chunkSet;
 char*				mftData;
 u_long				mftSize;
 u_long				mftWanted;

 // Get the chunk data
 chunkSet = getChunkSet();
 if (chunkSet == NULL)
 	return (KCS_INTERNAL_CLASS_CORRUPTED);

 //Get the size
 mftSize = chunkSet->getChunkSize(&aStat, myChunkId);
 if (aStat != KCS_SUCCESS)
 	return(aStat);

 //Make space for the data
 mftData = NULL;
 if ((mftData = malloc((u_int)mftSize)) == NULL) {
 	return (KCS_MEM_ALLOC_ERR);
 }

 //Read it
 aStat = chunkSet->readChunk(myChunkId, mftData, &mftWanted,
 				mftSize);
 if (aStat != KCS_SUCCESS)
 	return (aStat);

 //Zero it out and write it back
 memset(mftData, 0, mftSize);
 aStat = chunkSet->writeChunk(myChunkId, mftData, mftSize);
 if (aStat != KCS_SUCCESS)
 	return (aStat);