|
1 /* |
|
2 * Copyright (c) 2007-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 * Note: This file may contain code to generate corrupt files for test purposes. |
|
16 * Such code is excluded from production builds by use of compiler defines; |
|
17 * it is recommended that such code should be removed if this code is ever published publicly. |
|
18 * more utility functions. |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 /** |
|
24 @file |
|
25 @internalComponent |
|
26 @released |
|
27 */ |
|
28 |
|
29 #ifndef __UTILITY_INTERFACE_H__ |
|
30 #define __UTILITY_INTERFACE_H__ |
|
31 |
|
32 #include <iostream> |
|
33 #include "commontypes.h" |
|
34 |
|
35 #ifdef _WIN32 |
|
36 #include <windows.h> |
|
37 #endif // _WIN32 |
|
38 |
|
39 // common interface for Windows and Linux |
|
40 |
|
41 wchar_t** CommandLineArgs(int &argc , char *argv[]); |
|
42 |
|
43 void cleanup(int argc, wchar_t **argv); |
|
44 |
|
45 int CompareTwoString(wchar_t* string ,wchar_t* option); |
|
46 |
|
47 int CompareNString(wchar_t* string ,wchar_t* option , int len); |
|
48 |
|
49 TUint64 GetSizeOfFile(HANDLE hFile); |
|
50 |
|
51 |
|
52 char* GetTempFile(); |
|
53 |
|
54 void TransferFileData(const wchar_t *Fromfile , char* Tofile); |
|
55 |
|
56 void* MakeSISOpenFile(const wchar_t *pszFilename, unsigned long dwAccessMode, unsigned long dwCreateFlags); |
|
57 |
|
58 int MakeSISDeleteFile(const wchar_t *pszFilename); |
|
59 |
|
60 // Converts a relative path to an absolute path under Win95 and WinNT |
|
61 int FullPath(wchar_t *pszAbsolutePath, const wchar_t *pszRelativePath, unsigned int maxLength); |
|
62 |
|
63 // skip unicode marker if present |
|
64 bool UnicodeMarker(void* hfile); |
|
65 |
|
66 bool CreateDir(const wchar_t* aPathName); |
|
67 int FileAttributes(const wchar_t* aFileName ); |
|
68 |
|
69 void WriteToFile(const std::wstring& aFileName, const TUint8* aFileData, int aFileLength); |
|
70 |
|
71 int GetErrorValue( void ); |
|
72 |
|
73 /** |
|
74 * Converts wide char (unicode) string to multibyte string |
|
75 * This interface is provided so that we can have different implementation |
|
76 * in windows and linux machine. |
|
77 * @param aSource string to be converted |
|
78 * @param aSourceLen Source len. If this is -1 then it will calculate the length of the source. |
|
79 * @param aTarget target location. |
|
80 * @param aTargetLen Space in the target location. |
|
81 * @param aCodePage Code page number (currently supported in windows only) |
|
82 * @return Number of bytes that make up the converted part of multibyte sequence. |
|
83 * If aTarget is NULL then the function will return the size needed to store |
|
84 * the complete conversion of the source string. |
|
85 */ |
|
86 int ConvertWideCharToMultiByte(const wchar_t* aSource, int aSourceLen, char* aTarget, int aTargetLen, TUint32 aCodePage = 0); |
|
87 /** |
|
88 * Converts multibyte string to wide char (unicode) |
|
89 * This interface is provided so that we can have different implementation |
|
90 * in windows and linux machine. |
|
91 * @param aSource string to be converted |
|
92 * @param aSourceLen Source len. If this is -1 then it will calculate the length of the source. |
|
93 * @param aTarget target location. |
|
94 * @param aTargetLen Space in the target location. |
|
95 * @param aCodePage Code page number (currently supported in windows only) |
|
96 * @return Number of bytes that make up the converted part of widechar sequence. |
|
97 * If aTarget is NULL then the function will return the size needed to store |
|
98 * the complete conversion of the source string. |
|
99 */ |
|
100 int ConvertMultiByteToWideChar(const char* aSource, int aSourceLen, wchar_t* aTarget, int aTargetLen, TUint32 aCodePage = 0); |
|
101 |
|
102 // interface for only Linux |
|
103 |
|
104 #ifdef __TOOLS2_LINUX__ |
|
105 #include <errno.h> |
|
106 |
|
107 // File attributes |
|
108 const int FILE_ATTRIBUTE_READONLY = 0x00000001; |
|
109 const int FILE_ATTRIBUTE_HIDDEN = 0x00000002; |
|
110 const int FILE_ATTRIBUTE_SYSTEM = 0x00000004; |
|
111 const int FILE_ATTRIBUTE_DIRECTORY = 0x00000010; |
|
112 const int FILE_ATTRIBUTE_ARCHIVE = 0x00000020; |
|
113 const int FILE_ATTRIBUTE_ENCRYPTED = 0x00000040; |
|
114 const int FILE_ATTRIBUTE_COMPRESSED = 0x00000800; |
|
115 const int FILE_ATTRIBUTE_OFFLINE = 0x00001000; |
|
116 |
|
117 |
|
118 // File creation errors |
|
119 const int ERROR_PATH_NOT_FOUND = ENOENT; |
|
120 const int ERROR_ACCESS_DENIED = EACCES; |
|
121 const int ERROR_ALREADY_EXISTS = EEXIST; |
|
122 const int ERROR_INVALID_NAME = EFAULT; |
|
123 |
|
124 unsigned long GetFileAttributesW(const wchar_t *filename); |
|
125 |
|
126 int _wunlink(const wchar_t* wc); |
|
127 |
|
128 void* GetStdHandle(unsigned long handle); |
|
129 |
|
130 int GetTempPathW(unsigned int maxlen, const wchar_t *ptr); |
|
131 // Implement WriteFile // Works in Linux |
|
132 int WriteFile(void *hFile, const void *buffer, |
|
133 unsigned long bytesToWrite, |
|
134 unsigned long *bytesWritten, |
|
135 void *overlap); |
|
136 |
|
137 // Implement SetFilePointer // Works in Linux |
|
138 unsigned long SetFilePointer(void *hFile, |
|
139 long distance, |
|
140 long *highword, |
|
141 unsigned long method); |
|
142 |
|
143 // Implement CloseHandle // Works in Linux |
|
144 int CloseHandle(void *fd); |
|
145 |
|
146 // Implement GetFileSize in Linux |
|
147 long int GetFileSize(void *hFile, unsigned long* HighWord); |
|
148 |
|
149 // Implement ReadFile in Linux |
|
150 int ReadFile(void *hFile, void *buffer, unsigned long bytesToRead, |
|
151 unsigned long *bytesRead, void *); |
|
152 |
|
153 // Implement RemoveDirectoryA in Linux |
|
154 int RemoveDirectoryA(const char *a); |
|
155 |
|
156 |
|
157 // Implement CreateFileA in Linux |
|
158 void* CreateFileA(const char *filename, unsigned long access, unsigned long sharing, |
|
159 void*, unsigned long creation, |
|
160 unsigned long attributes, void*); |
|
161 |
|
162 // Implement CreateDirectoryA in Linux |
|
163 int CreateDirectoryA(const char *pathname, void*); |
|
164 |
|
165 // Implement WriteConsole in Linux |
|
166 void WriteConsole(void* handle,const void *pwNameEnt, unsigned long len, |
|
167 unsigned long *nosOfByteWritten, void* reserved); |
|
168 |
|
169 // Wide character support of WriteConsole |
|
170 void WriteConsoleW(void* handle,const void *pwNameEnt, unsigned long len, |
|
171 unsigned long *nosOfByteWritten, void* reserved); |
|
172 |
|
173 // Permission changes of file |
|
174 int _wchmod(const wchar_t *filename, unsigned long mod); |
|
175 |
|
176 // Get a current working directory |
|
177 int _wgetcwd(const wchar_t *directory , unsigned long length); |
|
178 |
|
179 // Get a temporary file Name |
|
180 int GetTempFileNameW(const wchar_t* tmpPath, const wchar_t* prefix, int unique, const wchar_t *filename ); |
|
181 |
|
182 // |
|
183 int DeleteFileA(const char* filename); |
|
184 |
|
185 bool IsBadReadPtr(const void* pv, unsigned long ulSize); |
|
186 |
|
187 bool IsBadWritePtr(const void* pv, unsigned long ulSize); |
|
188 |
|
189 char* itoa( int value, char* result, int base ); |
|
190 |
|
191 #endif // __TOOLS2_LINUX__ |
|
192 |
|
193 #if 0 |
|
194 inline std::ostream& operator<<(std::ostream& aStream, TUint64 aValue) |
|
195 { |
|
196 char buffer[20]; |
|
197 sprintf(buffer,"%I64d", aValue); |
|
198 aStream << buffer; |
|
199 return aStream; |
|
200 } |
|
201 #endif |
|
202 |
|
203 #endif // __UTILITY_INTERFACE_H__ |