|
1 /* |
|
2 * Copyright (c) 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 "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 #ifndef H_UTL_H |
|
19 #define H_UTL_H |
|
20 // |
|
21 #include <stdio.h> |
|
22 |
|
23 #ifdef __VC32__ |
|
24 #ifdef __MSVCDOTNET__ |
|
25 #include <iostream> |
|
26 #include <strstream> |
|
27 #include <fstream> |
|
28 using namespace std; |
|
29 #else //!__MSVCDOTNET__ |
|
30 #include <iostream.h> |
|
31 #include <strstrea.h> |
|
32 #include <fstream.h> |
|
33 #endif //__MSVCDOTNET__ |
|
34 #else //!__VC32__ |
|
35 #include <iostream.h> |
|
36 #include <strstream.h> |
|
37 #include <fstream.h> |
|
38 #endif // __VC32__ |
|
39 |
|
40 #ifdef __LINUX__ |
|
41 #include <sys/types.h> |
|
42 #include <sys/stat.h> |
|
43 #include <unistd.h> |
|
44 #include <ctype.h> |
|
45 |
|
46 #define _close close |
|
47 #define _filelength filelength |
|
48 #define _lseek lseek |
|
49 #define _read read |
|
50 #define _snprintf snprintf |
|
51 #define _vsnprintf vsnprintf |
|
52 |
|
53 // linux case insensitive stromg comparisons have different names |
|
54 #define stricmp strcasecmp |
|
55 #define _stricmp strcasecmp |
|
56 #define strnicmp strncasecmp |
|
57 |
|
58 // to fix the linux problem: memcpy does not work with overlapped areas. |
|
59 #define memcpy memmove |
|
60 |
|
61 // hand-rolled strupr function for converting a string to all uppercase |
|
62 char* strupr(char *a); |
|
63 |
|
64 // return the length of a file |
|
65 off_t filelength (int filedes); |
|
66 |
|
67 #endif //__LINUX__ |
|
68 |
|
69 #include <e32defwrap.h> |
|
70 |
|
71 #define ALIGN4K(a) ((a+0xfff)&0xfffff000) |
|
72 #define ALIGN4(a) ((a+0x3)&0xfffffffc) |
|
73 |
|
74 |
|
75 #ifdef HEAPCHK |
|
76 #define NOIMAGE |
|
77 #define WIN32_LEAN_AND_MEAN |
|
78 #include <windows.h> |
|
79 void HeapCheck(); |
|
80 #endif |
|
81 #define Print H.PrintString |
|
82 // |
|
83 const TInt KMaxStringLength=0x400; |
|
84 // |
|
85 |
|
86 class HMem |
|
87 { |
|
88 public: |
|
89 static TAny* Alloc(TAny * const aBaseAddress,const TUint32 aImageSize); |
|
90 static TAny* AllocZ( const TUint32 aImageSize ); |
|
91 static void Free(TAny * const aMem); |
|
92 static void Copy(TAny * const aDestAddr,const TAny * const aSourceAddr,const TUint32 aLength); |
|
93 static void Move(TAny * const aDestAddr,const TAny * const aSourceAddr,const TUint32 aLength); |
|
94 static void Set(TAny * const aDestAddr, const TUint8 aFillChar, const TUint32 aLength); |
|
95 static void FillZ(TAny * const aDestAddr, const TUint32 aLength); |
|
96 |
|
97 static TUint CheckSum(TUint *aPtr, TInt aSize); |
|
98 static TUint CheckSum8(TUint8 *aPtr, TInt aSize); |
|
99 static TUint CheckSumOdd8(TUint8 *aPtr, TInt aSize); |
|
100 static TUint CheckSumEven8(TUint8 *aPtr, TInt aSize); |
|
101 |
|
102 static void Crc32(TUint32& aCrc, const TAny* aPtr, TInt aLength); |
|
103 }; |
|
104 |
|
105 |
|
106 template <class T,class S> |
|
107 inline T* PtrAdd(T* aPtr,S aVal) |
|
108 {return((T*)(((TUint8*)aPtr)+aVal));} |
|
109 |
|
110 template <class T> |
|
111 inline T Min(T aLeft,T aRight) |
|
112 {return(aLeft<aRight ? aLeft : aRight);} |
|
113 |
|
114 |
|
115 #endif |