Beispiel #1
0
/** Reads a descriptor setting.
@param aKey Key of setting to be read.
@param aValue Returns the value of the setting if it is a descriptor.
@return
	KErrNone if successful,
	KErrNotFound if the setting does not exist,
	KErrArgument if the setting exists but is not a descriptor,
	KErrOverflow if the descriptor is too small to receive the value in the repository,
	plus other system-wide error codes.
@post Transactions fail only on those "other system-wide error codes".
@capability Dependent Caller must satisfy the read access policy of that key in the repository.
*/
EXPORT_C TInt CRepository::Get(TUint32 aKey, TDes16& aValue)
	{
	TPtr8 ptr8((TUint8*)aValue.Ptr(), 0, aValue.MaxSize());
	TInt ret=Get(aKey,ptr8);
	if (ret==KErrNone)
		aValue.SetLength(ptr8.Length()/2);
	return ret;
	}
/**
Reads data from the stream buffer into the specified descriptor.
On return, contains the data read from the stream buffer

@param aDes The target descriptor for the data read from the stream buffer
@param aLength The maximum number of bytes to be read
@return KErrNone If all bytes read successfully.
@return	KErrCorrupt If reading fails.
@return KErrEof If end of file is reached.
@return ... Any one of the system-wide error codes for other errors.
*/
EXPORT_C TInt RZipFileMemberReaderStream::Read(TDes16& aDes, TInt aLength)
{
	TUint32 numBytesRead = 0;
	TInt err = Read(CONST_CAST(TByte*,(const TByte*)aDes.Ptr()), 2*aLength, &numBytesRead);
	if (err != KErrNone)
	{
		aDes.SetLength( (err==KErrEof) ? numBytesRead>>2 : 0 );
		return err;
	}
Beispiel #3
0
/** Reads a descriptor setting.
@param aKey Key of setting to be read.
@param aValue Returns the value of the setting if it is a descriptor.
@param aActualLength Returns the actual length of the setting if it is a descriptor.
@return
	KErrNone if successful,
	KErrNotFound if the setting does not exist,
	KErrArgument if the setting exists but is not a descriptor,
	KErrOverflow if the descriptor is too small to receive the value in the repository,
	plus other system-wide error codes.
@post Transactions fail only on those "other system-wide error codes".
@capability Dependent Caller must satisfy the read access policy of that key in the repository.
*/
EXPORT_C TInt CRepository::Get(TUint32 aKey, TDes16& aValue, TInt& aActualLength)
	{
	TInt actualLength8;
	TPtr8 ptr8((TUint8*)aValue.Ptr(), 0, aValue.MaxSize());
	TInt ret=Get(aKey,ptr8,actualLength8);
	aValue.SetLength(ptr8.Length()/2);			
	aActualLength=actualLength8/2;		
	return ret;
	}
Beispiel #4
0
void CEnvironment::ConstructL(TUint aCount, TDes16& aBuffer)
//
// Set up the environment from a descriptor. If this leaves then
// the CEnvironment destructor will be able to clean up properly.
//
	{
	// always allocate at least one slot - makes life easier elsewhere
	TInt bytes = (aCount+1)*sizeof(TEnvVar);
	iVars=(TEnvVar*) User::AllocL(bytes);
	Mem::FillZ(iVars,bytes);
	iCount=aCount+1;

	const TText16* data=aBuffer.Ptr();
	for (TUint i=0; i<aCount; ++i)
		iVars[i].ConstructL(data);
	}
 /**
   * Converts a descriptor of type TBuf16 to character stream
   *
   * @param aSrc is the descriptor to be converted , aDes is the 
   * reference to the character sream where the result of conversion 
   * is stored , n_size specifies the conversion size of the string 
   * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, 
   * -2 is EInvalidSize , -4 is EInvalidPointer, -8 is EInvalidWCSSequence)
   */
EXPORT_C int Tbuf16ToChar(TDes16& aSrc, char* aDes, int& n_size)
{	
    unsigned int ilen = aSrc.Length();
    int retval = ESuccess;
    wchar_t *temp16String = NULL;
    int minusone = -1;
    
    if (0 == ilen)
    {
    	return EDescriptorNoData;
    }
    else if(!aDes)
    {
    	return EInvalidPointer;
    }
    
    else if(n_size < ilen*2+1)
    {
    	n_size = ilen*2;
    	return EInvalidSize;
    }
        		
	temp16String = new wchar_t [ilen+1];
	if (!temp16String)
	{
		return EInsufficientSystemMemory;
	}
	
	wmemcpy(temp16String, (const wchar_t *)aSrc.Ptr(), ilen);
	temp16String[ilen] = L'\0'; 	
	
	if(minusone != wcstombs(aDes, (const wchar_t*)temp16String, ilen*2))
	{
	    aDes[ilen*2] = '\0'; 
	}
	else 
	{
		retval = EInvalidWCSSequence;
	}
	
	delete []temp16String;	
	return retval;
}
void CMemSpyMemStreamReader::ReadL( TDes16& aDes )
    {
    // The kernel driver only ever writes narrow descriptors.
    // However, we can expand them to be UCS2
    const TInt length = ReadInt32L();

    // Need to check the remaining text is actually present...
    IsAvailableL( length );

    // Set final length in descriptor
    aDes.SetLength( length );

    // Read each char
    TUint16* dest = const_cast< TUint16* >( aDes.Ptr() );
    for( TInt i=0; i<length; i++ )
        {
        *dest++ = *iCurrent++;
        }
    }
 /**
   * Converts a descriptor of type RBuf16 to Wstring
   *
   * @param aSrc is the descriptor to be converted , aDes is the 
   * reference to the Wstring array where the result of conversion 
   * is stored  
   * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, 
   *  -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData)
   */
EXPORT_C int Rbuf16ToWstring(TDes16& aSrc, wstring& aDes)
{
    unsigned int ilen = aSrc.Length();
    if (0 == ilen)
    {
    	return EDescriptorNoData;
    }
    
    wchar_t* buf = new wchar_t[ilen+1];
    if(!buf)
    {
    	return EInsufficientSystemMemory;
    }
    
   	wmemcpy (buf,(wchar_t *)aSrc.Ptr(), ilen);
    buf[ilen]=L'\0';
    
    aDes.assign(buf);
	delete[] buf;
	
	return ESuccess;
}
EXPORT_C int Tbuf16ToWstring(TDes16& aSrc, wstring& aDes)
{	
   
    unsigned int ilen = aSrc.Length();
    if (0 == ilen)
	{
		return EDescriptorNoData;
	}
	
	wchar_t* wcharString = new wchar_t[ilen+1];
	if (!wcharString)
	{
		return EInsufficientSystemMemory;
	}
	
	wmemcpy((wchar_t*)wcharString, (const wchar_t*)aSrc.Ptr(), ilen);
	wcharString[ilen] = L'\0';
	
	aDes.assign(wcharString);
	
	delete []wcharString;
	return ESuccess;
}