Exemple #1
0
static int ReadFromFile(FILE *fd, String buffer, 
			String *startPos, String *endPos)
{
  int num_read=0;
  int chars_to_read;
  long available=0;
  
  available = numChars(fileno(fd));
  chars_to_read = MIN(MAX_LONG_MESSAGE - (*endPos - *startPos),
		      available);
  if (chars_to_read > 0) {
    num_read = read(fileno(fd), *endPos, chars_to_read);
    *endPos += num_read;
  }
  return(num_read);
}
void CMTPTypeString::ConstructL(const TDesC& aString)
    {
    if (aString.Length() > KMTPMaxStringCharactersLength)
        {
        User::Leave(KErrArgument);            
        }
    
    // Allocate string storage.
    TUint numChars(aString.Length());
    if (numChars)
        {
        numChars += KMTPNullCharLen;   
        }
    ReAllocBufferL(numChars);
    
    // Append the String Characters.
    if (numChars > 0)
        {
        iStringChars.Copy(aString);
        }
    }
void CMTPTypeString::ReAllocBufferL(TUint aNumNullTerminatedChars)
    {
    if (aNumNullTerminatedChars > KMTPMaxStringLength)
        {
        User::Leave(KErrOverflow);            
        }
        
    // Delete the current buffer
    iBuffer.Close();
    iStringChars.Set(NULL, 0, 0);
    
    // Allocate a new buffer.
    if (aNumNullTerminatedChars > 0)
        {  
        /*
        Allocate storage for both the NumChars and String Characters fields. A single 
        alignment byte is pre-pended to force String Characters to be 16-bit aligned.
        */
        iBuffer.CreateMaxL(KMTPAlignmentSize + KMTPNumCharsSize + (aNumNullTerminatedChars * KMTPCharSize));
        
        // Insert the terminating NULL character.
        TUint numChars(aNumNullTerminatedChars - KMTPNullCharLen);
        memcpy(&iBuffer[KMTPStringCharactersOffset + (numChars * KMTPCharSize)], &KMTPNullChar, KMTPCharSize);
        
        // Set the String Characters pointer.
        iStringChars.Set(reinterpret_cast<TUint16*>(&iBuffer[KMTPStringCharactersOffset]), numChars, numChars);
        }
    else
        {       
        /*
        Allocate storage for the NumChars field only. A single alignment byte 
        is pre-pended to force String Characters to be 16-bit aligned.
        */
        iBuffer.CreateMaxL(KMTPNumCharsSize + KMTPAlignmentSize);
        }
        
    // Insert the NumChars value
    iBuffer[KMTPNumCharsOffset] = aNumNullTerminatedChars;
    }