securityanddataprivacytools/securitytools/certapp/store--/e32base.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <errno.h>
       
    21 #include "stringconv.h"
       
    22 #include "logger.h"
       
    23 #include <f32file.h>
       
    24 
       
    25 void Panic(TInt aCode)
       
    26 {
       
    27 	dbg << Log::Indent() << "Panic(" << aCode << ")" << Log::Endl();
       
    28 	FatalError();
       
    29 }
       
    30 
       
    31 void User::LeaveIfError(TInt aError)
       
    32 {
       
    33 	if(aError<0) User::Leave(aError);
       
    34 }
       
    35 
       
    36 void User::Invariant()
       
    37 { 
       
    38 	FatalError();
       
    39 }
       
    40 void User::Panic(const TDesC &aCategory, TInt aReason) 
       
    41 { 
       
    42 	dbg << Log::Indent() << "User::Panic('" << stringFromUtf16(aCategory) << "'," << aReason << ") called" << Log::Endl();
       
    43 	FatalError(); 
       
    44 }
       
    45 
       
    46 void User::Leave(TInt aReason) 
       
    47 { 
       
    48 	dbg << Log::Indent() << "User::Leave(" << aReason << ") - Not supported by this port" << Log::Endl();
       
    49 	FatalError(); 
       
    50 }
       
    51 
       
    52 TDesC8::TDesC8()
       
    53 	: iCurrentLength(0)
       
    54 {
       
    55 }
       
    56 
       
    57 TDesC8::TDesC8(const TDesC8 &aRef)
       
    58 	: iCurrentLength(aRef.iCurrentLength)
       
    59 {
       
    60 }
       
    61 
       
    62 TDesC8::TDesC8(TInt aLength)
       
    63 	: iCurrentLength(aLength)
       
    64 {
       
    65 }
       
    66 
       
    67 TBool TDesC8::operator==(const TDesC8 &aDes) const
       
    68 {
       
    69 	if(Length() != aDes.Length())
       
    70 		{
       
    71 		return EFalse;
       
    72 		}
       
    73 	
       
    74 	if(memcmp(Ptr(), aDes.Ptr(), Length()) == 0)
       
    75 		{
       
    76 		return ETrue; // Identical
       
    77 		}
       
    78 	return EFalse;
       
    79 }
       
    80 
       
    81 
       
    82 
       
    83 TDes8::TDes8()
       
    84 	: TDesC8(0), iMaxLength(0)
       
    85 {
       
    86 }
       
    87 
       
    88 TDes8::TDes8(const TDes8 &aRef)
       
    89 	: TDesC8(aRef), iMaxLength(aRef.iMaxLength)
       
    90 {
       
    91 }
       
    92 
       
    93 
       
    94 
       
    95 TDes8::TDes8(TInt aLength,TInt aMaxLength)
       
    96 	: TDesC8(aLength), iMaxLength(aMaxLength)
       
    97 {
       
    98 }
       
    99 
       
   100 void TDes8::Copy(const TDesC16 &aDes)
       
   101 {
       
   102 	TInt len=aDes.Length();
       
   103 	SetLength(len);
       
   104 	const TUint16 *pS=aDes.Ptr();
       
   105 	const TUint16 *pE=pS+len;
       
   106 	TUint8 *pT=const_cast<TUint8 *>(Ptr());
       
   107 	while (pS<pE)
       
   108 		{
       
   109 		TUint c=(*pS++);
       
   110 		if (c>=0x100)
       
   111 			c=1;
       
   112 		*pT++=(TUint8)c;
       
   113 		}
       
   114 }
       
   115 
       
   116 
       
   117 
       
   118 void TDes8::SetLength(TInt aLength)
       
   119 {
       
   120 	if(aLength < 0 || aLength > iMaxLength) FatalError();
       
   121 	iCurrentLength = aLength;
       
   122 }
       
   123 	
       
   124 
       
   125 TPtr8::TPtr8(const TPtr8 &aRef)
       
   126 	: TDes8(aRef), iPtr(aRef.iPtr)
       
   127 {
       
   128 }
       
   129 
       
   130 TPtr8 &TPtr8::operator=(const TPtr8 &aRhs)
       
   131 {
       
   132 	if(this == &aRhs) return *this; // handle self assignment
       
   133 	if(aRhs.Length() > MaxLength()) FatalError();
       
   134 	memcpy(iPtr, aRhs.Ptr(), aRhs.Length());
       
   135 	SetLength(aRhs.Length());
       
   136 
       
   137 	return *this;
       
   138 }
       
   139 
       
   140 const TUint8 *TPtr8::Ptr() const
       
   141 {
       
   142 	return iPtr;
       
   143 }
       
   144 
       
   145 const TUint8 &TPtr8::operator[](TInt anIndex) const
       
   146 {
       
   147 	if(anIndex < 0 || anIndex >= Length())
       
   148 		{
       
   149 		dbg << Log::Indent() << "TPtrC8 bounds check failure" << Log::Endl();
       
   150 		FatalError();
       
   151 		}
       
   152 	return iPtr[anIndex];
       
   153 }
       
   154 
       
   155 
       
   156 void TPtr8::Append(TChar aChar)
       
   157 {
       
   158 	if(iCurrentLength+1 > iMaxLength)
       
   159 		{
       
   160 		dbg << Log::Indent() << "TPtr8::Append range check failure" << Log::Endl();
       
   161 		FatalError();
       
   162 		}
       
   163 	iPtr[iCurrentLength++] = aChar;
       
   164 }
       
   165 
       
   166 
       
   167 
       
   168 
       
   169 
       
   170 TPtrC8::TPtrC8(const TPtrC8 &aRef)
       
   171 	: TDesC8(aRef), iPtr(aRef.iPtr)
       
   172 {
       
   173 }
       
   174 
       
   175 TPtrC8 &TPtrC8::operator=(const TPtrC8 &aRhs)
       
   176 {
       
   177 	if(this == &aRhs) return *this; // handle self assignment
       
   178 	if(aRhs.Length() > Length()) FatalError();
       
   179 	memcpy(const_cast<TUint8 *>(iPtr), aRhs.Ptr(), aRhs.Length());
       
   180 
       
   181 	return *this;
       
   182 }
       
   183 
       
   184 void TPtrC8::Set(TUint8 *aBuf, TInt aLength)
       
   185 {
       
   186 	iPtr = aBuf,
       
   187 	iCurrentLength = aLength;
       
   188 }
       
   189 
       
   190 const TUint8 *TPtrC8::Ptr() const
       
   191 {
       
   192 	return iPtr;
       
   193 }
       
   194 
       
   195 const TUint8 &TPtrC8::operator[](TInt anIndex) const
       
   196 {
       
   197 	if(anIndex < 0 || anIndex >= Length())
       
   198 		{
       
   199 		dbg << Log::Indent() << "TPtrC8 bounds check failure" << Log::Endl();
       
   200 		FatalError();
       
   201 		}
       
   202 	return iPtr[anIndex];
       
   203 }
       
   204 
       
   205 
       
   206 
       
   207 TDesC16::TDesC16()
       
   208 	: iCurrentLength(0)
       
   209 {
       
   210 }
       
   211 
       
   212 TDesC16::TDesC16(const TDesC16 &aRef)
       
   213 	: iCurrentLength(aRef.iCurrentLength)
       
   214 {
       
   215 }
       
   216 
       
   217 TDesC16::TDesC16(TInt aLength)
       
   218 	: iCurrentLength(aLength)
       
   219 {
       
   220 }
       
   221 
       
   222 
       
   223 TDes16::TDes16()
       
   224 	: TDesC16(0), iMaxLength(0)
       
   225 {
       
   226 }
       
   227 
       
   228 TDes16::TDes16(const TDes16 &aRef)
       
   229 	: TDesC16(aRef), iMaxLength(aRef.iMaxLength)
       
   230 {
       
   231 }
       
   232 
       
   233 
       
   234 
       
   235 TDes16::TDes16(TInt aLength,TInt aMaxLength)
       
   236 	: TDesC16(aLength), iMaxLength(aMaxLength)
       
   237 {
       
   238 }
       
   239 
       
   240 
       
   241 void TDes16::SetLength(TInt aLength)
       
   242 {
       
   243 	if(aLength < 0 || aLength > iMaxLength) FatalError();
       
   244 	iCurrentLength = aLength;
       
   245 }
       
   246 
       
   247 TBool TDesC16::operator==(const TDesC8 &aDes) const
       
   248 {
       
   249 	if(Length() != aDes.Length())
       
   250 		{
       
   251 		return EFalse;
       
   252 		}
       
   253 	
       
   254 	if(memcmp(Ptr(), aDes.Ptr(), Length()*2) == 0)
       
   255 		{
       
   256 		return ETrue; // Identical
       
   257 		}
       
   258 	return EFalse;
       
   259 }
       
   260 
       
   261 
       
   262 TPtrC16::TPtrC16(const TPtrC16 &aRef)
       
   263 	: TDesC16(aRef), iPtr(aRef.iPtr)
       
   264 {
       
   265 }
       
   266 
       
   267 TPtrC16 &TPtrC16::operator=(const TPtrC16 &aRhs)
       
   268 {
       
   269 	if(this == &aRhs) return *this; // handle self assignment
       
   270 	if(aRhs.Length() > Length()) FatalError();
       
   271 	memcpy(const_cast<TUint16 *>(iPtr), aRhs.Ptr(), aRhs.Length()*2);
       
   272 
       
   273 	return *this;
       
   274 }
       
   275 
       
   276 void TPtrC16::Set(TUint16 *aBuf, TInt aLength)
       
   277 {
       
   278 	iPtr = aBuf,
       
   279 	iCurrentLength = aLength;
       
   280 }
       
   281 
       
   282 
       
   283 const TUint16 *TPtrC16::Ptr() const
       
   284 {
       
   285 	return iPtr;
       
   286 }
       
   287 
       
   288 const TUint16 &TPtrC16::operator[](TInt anIndex) const
       
   289 {
       
   290 	if(anIndex < 0 || anIndex >= Length())
       
   291 		{
       
   292 		dbg << Log::Indent() << "TPtrC16 bounds check failure" << Log::Endl();
       
   293 		FatalError();
       
   294 		}
       
   295 	
       
   296 	return iPtr[anIndex];
       
   297 }
       
   298 
       
   299 
       
   300 
       
   301 
       
   302 TPtr16::TPtr16(const TPtr16 &aRef)
       
   303 	: TDes16(aRef), iPtr(aRef.iPtr)
       
   304 {
       
   305 }
       
   306 
       
   307 TPtr16 &TPtr16::operator=(const TPtr16 &aRhs)
       
   308 {
       
   309 	if(this == &aRhs) return *this; // handle self assignment
       
   310 	if(aRhs.Length() > MaxLength()) FatalError();
       
   311 	memcpy(iPtr, aRhs.Ptr(), aRhs.Length()*sizeof(TUint16));
       
   312 	SetLength(aRhs.Length());
       
   313 
       
   314 	return *this;
       
   315 }
       
   316 
       
   317 void TPtr16::Copy(const TDesC8 &aDes)
       
   318 {
       
   319 	// This is not quite 100% compatible because it does a correct
       
   320 	// UTF-8 to UCS-2 conversion, instead of just stuffing in zeros.
       
   321 	TInt outLength = 0;
       
   322 	TText *outBuf = utf16FromUtf8(aDes.Ptr(), aDes.Length(), outLength);
       
   323 
       
   324 	if(outLength > MaxLength()) FatalError();
       
   325 	memcpy(iPtr, outBuf, outLength*2);
       
   326 	SetLength(outLength);
       
   327 	delete [] outBuf;
       
   328 }
       
   329 
       
   330 
       
   331 const TUint16 *TPtr16::Ptr() const
       
   332 {
       
   333 	return iPtr;
       
   334 }
       
   335 
       
   336 const TUint16 &TPtr16::operator[](TInt anIndex) const
       
   337 {
       
   338 	if(anIndex < 0 || anIndex >= Length())
       
   339 		{
       
   340 		dbg << Log::Indent() << "TPtr16 bounds check failure" << Log::Endl();
       
   341 		FatalError();
       
   342 		}
       
   343 	
       
   344 	return iPtr[anIndex];
       
   345 }
       
   346 
       
   347 void TPtr16::Append(TChar aChar)
       
   348 {
       
   349 	if(iCurrentLength+1 > iMaxLength)
       
   350 		{
       
   351 		dbg << Log::Indent() << "TPtr16::Append range check failure" << Log::Endl();
       
   352 		FatalError();
       
   353 		}
       
   354 	iPtr[iCurrentLength++] = aChar;
       
   355 }
       
   356 
       
   357 
       
   358 
       
   359 
       
   360 
       
   361 
       
   362 TLIT16::TLIT16(const char *aStr)
       
   363 	: iDes(0,0)
       
   364 {
       
   365 
       
   366 
       
   367 	// Expand UTF-8 into internal UTF-16LE representation
       
   368 	TInt outputWords = 0;
       
   369 	TText *outputBuf = utf16FromUtf8((TUint8 *)aStr, strlen(aStr), outputWords);
       
   370 	// Work out actual string length and save the buffer and ptr in out descriptor
       
   371 	iDes.Set(outputBuf, outputWords);
       
   372 }
       
   373 
       
   374 TLIT16::TLIT16(const TLIT16 &aRef)
       
   375 	: iDes(aRef.iDes.Ptr(), aRef.iDes.Length())
       
   376 {
       
   377 }
       
   378 
       
   379 
       
   380 TLIT16::~TLIT16()
       
   381 {
       
   382 	// May leak here, but TLITs should be at global scope anyway...
       
   383 }
       
   384 
       
   385 
       
   386 const TDesC16* TLIT16::operator&() const
       
   387 {
       
   388 	return &iDes;
       
   389 }
       
   390 
       
   391 TLIT16::operator const TDesC16&() const
       
   392 {
       
   393 	return iDes;
       
   394 }
       
   395 
       
   396 const TDesC16& TLIT16::operator()() const
       
   397 {
       
   398 	return iDes;
       
   399 }
       
   400 
       
   401 
       
   402 TLIT8::TLIT8(const char *aStr)
       
   403 	: TPtrC8((const TUint8 *)aStr, strlen(aStr))
       
   404 {
       
   405 }
       
   406 
       
   407 TLIT8::TLIT8(const TLIT8 &aRef)
       
   408 	: TPtrC8(aRef)
       
   409 {
       
   410 }
       
   411 
       
   412 
       
   413 
       
   414 void CleanupStack::PopAndDestroy(RArrayBase *aRArray)
       
   415 {
       
   416 	aRArray->Close();
       
   417 }
       
   418 
       
   419 
       
   420 void CleanupStack::PopAndDestroy(RFs *aFs)
       
   421 {
       
   422 	aFs->Close();
       
   423 }
       
   424 
       
   425 void PushL(void *)
       
   426 {
       
   427 }
       
   428 
       
   429 
       
   430 // End of file