Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: core/src/fxcrt/fx_extension.cpp

Issue 1171733003: Remove typdefs for pointer types in fx_system.h (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual fixes. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxcrt/fx_basic_wstring.cpp ('k') | core/src/fxcrt/fx_xml_parser.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../include/fxcrt/fx_ext.h" 7 #include "../../include/fxcrt/fx_ext.h"
8 #include "extension.h" 8 #include "extension.h"
9 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 9 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
10 #include <wincrypt.h> 10 #include <wincrypt.h>
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 FX_BOOL FX_File_Flush(FX_HFILE hFile) 73 FX_BOOL FX_File_Flush(FX_HFILE hFile)
74 { 74 {
75 FXSYS_assert(hFile != NULL); 75 FXSYS_assert(hFile != NULL);
76 return ((IFXCRT_FileAccess*)hFile)->Flush(); 76 return ((IFXCRT_FileAccess*)hFile)->Flush();
77 } 77 }
78 FX_BOOL FX_File_Truncate(FX_HFILE hFile, FX_FILESIZE szFile) 78 FX_BOOL FX_File_Truncate(FX_HFILE hFile, FX_FILESIZE szFile)
79 { 79 {
80 FXSYS_assert(hFile != NULL); 80 FXSYS_assert(hFile != NULL);
81 return ((IFXCRT_FileAccess*)hFile)->Truncate(szFile); 81 return ((IFXCRT_FileAccess*)hFile)->Truncate(szFile);
82 } 82 }
83 IFX_FileStream* FX_CreateFileStream(FX_LPCSTR filename, FX_DWORD dwModes) 83 IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, FX_DWORD dwModes)
84 { 84 {
85 IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(); 85 IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create();
86 if (!pFA) { 86 if (!pFA) {
87 return NULL; 87 return NULL;
88 } 88 }
89 if (!pFA->Open(filename, dwModes)) { 89 if (!pFA->Open(filename, dwModes)) {
90 pFA->Release(); 90 pFA->Release();
91 return NULL; 91 return NULL;
92 } 92 }
93 return new CFX_CRTFileStream(pFA); 93 return new CFX_CRTFileStream(pFA);
94 } 94 }
95 IFX_FileStream* FX_CreateFileStream(FX_LPCWSTR filename, FX_DWORD dwModes) 95 IFX_FileStream* FX_CreateFileStream(const FX_WCHAR* filename, FX_DWORD dwModes)
96 { 96 {
97 IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(); 97 IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create();
98 if (!pFA) { 98 if (!pFA) {
99 return NULL; 99 return NULL;
100 } 100 }
101 if (!pFA->Open(filename, dwModes)) { 101 if (!pFA->Open(filename, dwModes)) {
102 pFA->Release(); 102 pFA->Release();
103 return NULL; 103 return NULL;
104 } 104 }
105 return new CFX_CRTFileStream(pFA); 105 return new CFX_CRTFileStream(pFA);
106 } 106 }
107 IFX_FileWrite* FX_CreateFileWrite(FX_LPCSTR filename) 107 IFX_FileWrite* FX_CreateFileWrite(const FX_CHAR* filename)
108 { 108 {
109 return FX_CreateFileStream(filename, FX_FILEMODE_Truncate); 109 return FX_CreateFileStream(filename, FX_FILEMODE_Truncate);
110 } 110 }
111 IFX_FileWrite* FX_CreateFileWrite(FX_LPCWSTR filename) 111 IFX_FileWrite* FX_CreateFileWrite(const FX_WCHAR* filename)
112 { 112 {
113 return FX_CreateFileStream(filename, FX_FILEMODE_Truncate); 113 return FX_CreateFileStream(filename, FX_FILEMODE_Truncate);
114 } 114 }
115 IFX_FileRead* FX_CreateFileRead(FX_LPCSTR filename) 115 IFX_FileRead* FX_CreateFileRead(const FX_CHAR* filename)
116 { 116 {
117 return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly); 117 return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly);
118 } 118 }
119 IFX_FileRead* FX_CreateFileRead(FX_LPCWSTR filename) 119 IFX_FileRead* FX_CreateFileRead(const FX_WCHAR* filename)
120 { 120 {
121 return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly); 121 return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly);
122 } 122 }
123 IFX_MemoryStream* FX_CreateMemoryStream(FX_LPBYTE pBuffer, size_t dwSize, FX_BOO L bTakeOver) 123 IFX_MemoryStream* FX_CreateMemoryStream(uint8_t* pBuffer, size_t dwSize, FX_BOOL bTakeOver)
124 { 124 {
125 return new CFX_MemoryStream(pBuffer, dwSize, bTakeOver); 125 return new CFX_MemoryStream(pBuffer, dwSize, bTakeOver);
126 } 126 }
127 IFX_MemoryStream* FX_CreateMemoryStream(FX_BOOL bConsecutive) 127 IFX_MemoryStream* FX_CreateMemoryStream(FX_BOOL bConsecutive)
128 { 128 {
129 return new CFX_MemoryStream(bConsecutive); 129 return new CFX_MemoryStream(bConsecutive);
130 } 130 }
131 #ifdef __cplusplus 131 #ifdef __cplusplus
132 extern "C" { 132 extern "C" {
133 #endif 133 #endif
134 FX_FLOAT FXSYS_tan(FX_FLOAT a) 134 FX_FLOAT FXSYS_tan(FX_FLOAT a)
135 { 135 {
136 return (FX_FLOAT)tan(a); 136 return (FX_FLOAT)tan(a);
137 } 137 }
138 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x) 138 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x)
139 { 139 {
140 return FXSYS_log(x) / FXSYS_log(b); 140 return FXSYS_log(x) / FXSYS_log(b);
141 } 141 }
142 FX_FLOAT FXSYS_strtof(FX_LPCSTR pcsStr, int32_t iLength, int32_t *pUsedLen) 142 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, int32_t iLength, int32_t *pUsedLen)
143 { 143 {
144 FXSYS_assert(pcsStr != NULL); 144 FXSYS_assert(pcsStr != NULL);
145 if (iLength < 0) { 145 if (iLength < 0) {
146 iLength = (int32_t)FXSYS_strlen(pcsStr); 146 iLength = (int32_t)FXSYS_strlen(pcsStr);
147 } 147 }
148 CFX_WideString ws = CFX_WideString::FromLocal(pcsStr, iLength); 148 CFX_WideString ws = CFX_WideString::FromLocal(pcsStr, iLength);
149 return FXSYS_wcstof(ws.c_str(), iLength, pUsedLen); 149 return FXSYS_wcstof(ws.c_str(), iLength, pUsedLen);
150 } 150 }
151 FX_FLOAT FXSYS_wcstof(FX_LPCWSTR pwsStr, int32_t iLength, int32_t *pUsedLen) 151 FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr, int32_t iLength, int32_t *pUsedLen )
152 { 152 {
153 FXSYS_assert(pwsStr != NULL); 153 FXSYS_assert(pwsStr != NULL);
154 if (iLength < 0) { 154 if (iLength < 0) {
155 iLength = (int32_t)FXSYS_wcslen(pwsStr); 155 iLength = (int32_t)FXSYS_wcslen(pwsStr);
156 } 156 }
157 if (iLength == 0) { 157 if (iLength == 0) {
158 return 0.0f; 158 return 0.0f;
159 } 159 }
160 int32_t iUsedLen = 0; 160 int32_t iUsedLen = 0;
161 FX_BOOL bNegtive = FALSE; 161 FX_BOOL bNegtive = FALSE;
(...skipping 24 matching lines...) Expand all
186 } else { 186 } else {
187 break; 187 break;
188 } 188 }
189 } 189 }
190 } 190 }
191 if (pUsedLen) { 191 if (pUsedLen) {
192 *pUsedLen = iUsedLen; 192 *pUsedLen = iUsedLen;
193 } 193 }
194 return bNegtive ? -fValue : fValue; 194 return bNegtive ? -fValue : fValue;
195 } 195 }
196 FX_LPWSTR FXSYS_wcsncpy(FX_LPWSTR dstStr, FX_LPCWSTR srcStr, size_t count) 196 FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, const FX_WCHAR* srcStr, size_t count)
197 { 197 {
198 FXSYS_assert(dstStr != NULL && srcStr != NULL && count > 0); 198 FXSYS_assert(dstStr != NULL && srcStr != NULL && count > 0);
199 for (size_t i = 0; i < count; ++i) 199 for (size_t i = 0; i < count; ++i)
200 if ((dstStr[i] = srcStr[i]) == L'\0') { 200 if ((dstStr[i] = srcStr[i]) == L'\0') {
201 break; 201 break;
202 } 202 }
203 return dstStr; 203 return dstStr;
204 } 204 }
205 int32_t FXSYS_wcsnicmp(FX_LPCWSTR s1, FX_LPCWSTR s2, size_t count) 205 int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count)
206 { 206 {
207 FXSYS_assert(s1 != NULL && s2 != NULL && count > 0); 207 FXSYS_assert(s1 != NULL && s2 != NULL && count > 0);
208 FX_WCHAR wch1 = 0, wch2 = 0; 208 FX_WCHAR wch1 = 0, wch2 = 0;
209 while (count-- > 0) { 209 while (count-- > 0) {
210 wch1 = (FX_WCHAR)FXSYS_tolower(*s1++); 210 wch1 = (FX_WCHAR)FXSYS_tolower(*s1++);
211 wch2 = (FX_WCHAR)FXSYS_tolower(*s2++); 211 wch2 = (FX_WCHAR)FXSYS_tolower(*s2++);
212 if (wch1 != wch2) { 212 if (wch1 != wch2) {
213 break; 213 break;
214 } 214 }
215 } 215 }
216 return wch1 - wch2; 216 return wch1 - wch2;
217 } 217 }
218 int32_t FXSYS_strnicmp(FX_LPCSTR s1, FX_LPCSTR s2, size_t count) 218 int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count)
219 { 219 {
220 FXSYS_assert(s1 != NULL && s2 != NULL && count > 0); 220 FXSYS_assert(s1 != NULL && s2 != NULL && count > 0);
221 FX_CHAR ch1 = 0, ch2 = 0; 221 FX_CHAR ch1 = 0, ch2 = 0;
222 while (count-- > 0) { 222 while (count-- > 0) {
223 ch1 = (FX_CHAR)FXSYS_tolower(*s1++); 223 ch1 = (FX_CHAR)FXSYS_tolower(*s1++);
224 ch2 = (FX_CHAR)FXSYS_tolower(*s2++); 224 ch2 = (FX_CHAR)FXSYS_tolower(*s2++);
225 if (ch1 != ch2) { 225 if (ch1 != ch2) {
226 break; 226 break;
227 } 227 }
228 } 228 }
229 return ch1 - ch2; 229 return ch1 - ch2;
230 } 230 }
231 FX_DWORD FX_HashCode_String_GetA(FX_LPCSTR pStr, int32_t iLength, FX_BOOL bIgnor eCase) 231 FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr, int32_t iLength, FX_BOOL b IgnoreCase)
232 { 232 {
233 FXSYS_assert(pStr != NULL); 233 FXSYS_assert(pStr != NULL);
234 if (iLength < 0) { 234 if (iLength < 0) {
235 iLength = (int32_t)FXSYS_strlen(pStr); 235 iLength = (int32_t)FXSYS_strlen(pStr);
236 } 236 }
237 FX_LPCSTR pStrEnd = pStr + iLength; 237 const FX_CHAR* pStrEnd = pStr + iLength;
238 FX_DWORD dwHashCode = 0; 238 FX_DWORD dwHashCode = 0;
239 if (bIgnoreCase) { 239 if (bIgnoreCase) {
240 while (pStr < pStrEnd) { 240 while (pStr < pStrEnd) {
241 dwHashCode = 31 * dwHashCode + FXSYS_tolower(*pStr++); 241 dwHashCode = 31 * dwHashCode + FXSYS_tolower(*pStr++);
242 } 242 }
243 } else { 243 } else {
244 while (pStr < pStrEnd) { 244 while (pStr < pStrEnd) {
245 dwHashCode = 31 * dwHashCode + *pStr ++; 245 dwHashCode = 31 * dwHashCode + *pStr ++;
246 } 246 }
247 } 247 }
248 return dwHashCode; 248 return dwHashCode;
249 } 249 }
250 FX_DWORD FX_HashCode_String_GetW(FX_LPCWSTR pStr, int32_t iLength, FX_BOOL bIgno reCase) 250 FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr, int32_t iLength, FX_BOOL bIgnoreCase)
251 { 251 {
252 FXSYS_assert(pStr != NULL); 252 FXSYS_assert(pStr != NULL);
253 if (iLength < 0) { 253 if (iLength < 0) {
254 iLength = (int32_t)FXSYS_wcslen(pStr); 254 iLength = (int32_t)FXSYS_wcslen(pStr);
255 } 255 }
256 FX_LPCWSTR pStrEnd = pStr + iLength; 256 const FX_WCHAR* pStrEnd = pStr + iLength;
257 FX_DWORD dwHashCode = 0; 257 FX_DWORD dwHashCode = 0;
258 if (bIgnoreCase) { 258 if (bIgnoreCase) {
259 while (pStr < pStrEnd) { 259 while (pStr < pStrEnd) {
260 dwHashCode = 1313 * dwHashCode + FXSYS_tolower(*pStr++); 260 dwHashCode = 1313 * dwHashCode + FXSYS_tolower(*pStr++);
261 } 261 }
262 } else { 262 } else {
263 while (pStr < pStrEnd) { 263 while (pStr < pStrEnd) {
264 dwHashCode = 1313 * dwHashCode + *pStr ++; 264 dwHashCode = 1313 * dwHashCode + *pStr ++;
265 } 265 }
266 } 266 }
267 return dwHashCode; 267 return dwHashCode;
268 } 268 }
269 #ifdef __cplusplus 269 #ifdef __cplusplus
270 } 270 }
271 #endif 271 #endif
272 #ifdef __cplusplus 272 #ifdef __cplusplus
273 extern "C" { 273 extern "C" {
274 #endif 274 #endif
275 FX_LPVOID FX_Random_MT_Start(FX_DWORD dwSeed) 275 void* FX_Random_MT_Start(FX_DWORD dwSeed)
276 { 276 {
277 FX_LPMTRANDOMCONTEXT pContext = FX_Alloc(FX_MTRANDOMCONTEXT, 1); 277 FX_LPMTRANDOMCONTEXT pContext = FX_Alloc(FX_MTRANDOMCONTEXT, 1);
278 pContext->mt[0] = dwSeed; 278 pContext->mt[0] = dwSeed;
279 FX_DWORD &i = pContext->mti; 279 FX_DWORD &i = pContext->mti;
280 FX_LPDWORD pBuf = pContext->mt; 280 FX_DWORD* pBuf = pContext->mt;
281 for (i = 1; i < MT_N; i ++) { 281 for (i = 1; i < MT_N; i ++) {
282 pBuf[i] = (1812433253UL * (pBuf[i - 1] ^ (pBuf[i - 1] >> 30)) + i); 282 pBuf[i] = (1812433253UL * (pBuf[i - 1] ^ (pBuf[i - 1] >> 30)) + i);
283 } 283 }
284 pContext->bHaveSeed = TRUE; 284 pContext->bHaveSeed = TRUE;
285 return pContext; 285 return pContext;
286 } 286 }
287 FX_DWORD FX_Random_MT_Generate(FX_LPVOID pContext) 287 FX_DWORD FX_Random_MT_Generate(void* pContext)
288 { 288 {
289 FXSYS_assert(pContext != NULL); 289 FXSYS_assert(pContext != NULL);
290 FX_LPMTRANDOMCONTEXT pMTC = (FX_LPMTRANDOMCONTEXT)pContext; 290 FX_LPMTRANDOMCONTEXT pMTC = (FX_LPMTRANDOMCONTEXT)pContext;
291 FX_DWORD v; 291 FX_DWORD v;
292 static FX_DWORD mag[2] = {0, MT_Matrix_A}; 292 static FX_DWORD mag[2] = {0, MT_Matrix_A};
293 FX_DWORD &mti = pMTC->mti; 293 FX_DWORD &mti = pMTC->mti;
294 FX_LPDWORD pBuf = pMTC->mt; 294 FX_DWORD* pBuf = pMTC->mt;
295 if ((int)mti < 0 || mti >= MT_N) { 295 if ((int)mti < 0 || mti >= MT_N) {
296 if (mti > MT_N && !pMTC->bHaveSeed) { 296 if (mti > MT_N && !pMTC->bHaveSeed) {
297 return 0; 297 return 0;
298 } 298 }
299 FX_DWORD kk; 299 FX_DWORD kk;
300 for (kk = 0; kk < MT_N - MT_M; kk ++) { 300 for (kk = 0; kk < MT_N - MT_M; kk ++) {
301 v = (pBuf[kk] & MT_Upper_Mask) | (pBuf[kk + 1] & MT_Lower_Mask); 301 v = (pBuf[kk] & MT_Upper_Mask) | (pBuf[kk + 1] & MT_Lower_Mask);
302 pBuf[kk] = pBuf[kk + MT_M] ^ (v >> 1) ^ mag[v & 1]; 302 pBuf[kk] = pBuf[kk + MT_M] ^ (v >> 1) ^ mag[v & 1];
303 } 303 }
304 for (; kk < MT_N - 1; kk ++) { 304 for (; kk < MT_N - 1; kk ++) {
305 v = (pBuf[kk] & MT_Upper_Mask) | (pBuf[kk + 1] & MT_Lower_Mask); 305 v = (pBuf[kk] & MT_Upper_Mask) | (pBuf[kk + 1] & MT_Lower_Mask);
306 pBuf[kk] = pBuf[kk + (MT_M - MT_N)] ^ (v >> 1) ^ mag[v & 1]; 306 pBuf[kk] = pBuf[kk + (MT_M - MT_N)] ^ (v >> 1) ^ mag[v & 1];
307 } 307 }
308 v = (pBuf[MT_N - 1] & MT_Upper_Mask) | (pBuf[0] & MT_Lower_Mask); 308 v = (pBuf[MT_N - 1] & MT_Upper_Mask) | (pBuf[0] & MT_Lower_Mask);
309 pBuf[MT_N - 1] = pBuf[MT_M - 1] ^ (v >> 1) ^ mag[v & 1]; 309 pBuf[MT_N - 1] = pBuf[MT_M - 1] ^ (v >> 1) ^ mag[v & 1];
310 mti = 0; 310 mti = 0;
311 } 311 }
312 v = pBuf[mti ++]; 312 v = pBuf[mti ++];
313 v ^= (v >> 11); 313 v ^= (v >> 11);
314 v ^= (v << 7) & 0x9d2c5680UL; 314 v ^= (v << 7) & 0x9d2c5680UL;
315 v ^= (v << 15) & 0xefc60000UL; 315 v ^= (v << 15) & 0xefc60000UL;
316 v ^= (v >> 18); 316 v ^= (v >> 18);
317 return v; 317 return v;
318 } 318 }
319 void FX_Random_MT_Close(FX_LPVOID pContext) 319 void FX_Random_MT_Close(void* pContext)
320 { 320 {
321 FXSYS_assert(pContext != NULL); 321 FXSYS_assert(pContext != NULL);
322 FX_Free(pContext); 322 FX_Free(pContext);
323 } 323 }
324 void FX_Random_GenerateMT(FX_LPDWORD pBuffer, int32_t iCount) 324 void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount)
325 { 325 {
326 FX_DWORD dwSeed; 326 FX_DWORD dwSeed;
327 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 327 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
328 if (!FX_GenerateCryptoRandom(&dwSeed, 1)) { 328 if (!FX_GenerateCryptoRandom(&dwSeed, 1)) {
329 FX_Random_GenerateBase(&dwSeed, 1); 329 FX_Random_GenerateBase(&dwSeed, 1);
330 } 330 }
331 #else 331 #else
332 FX_Random_GenerateBase(&dwSeed, 1); 332 FX_Random_GenerateBase(&dwSeed, 1);
333 #endif 333 #endif
334 FX_LPVOID pContext = FX_Random_MT_Start(dwSeed); 334 void* pContext = FX_Random_MT_Start(dwSeed);
335 while (iCount -- > 0) { 335 while (iCount -- > 0) {
336 *pBuffer ++ = FX_Random_MT_Generate(pContext); 336 *pBuffer ++ = FX_Random_MT_Generate(pContext);
337 } 337 }
338 FX_Random_MT_Close(pContext); 338 FX_Random_MT_Close(pContext);
339 } 339 }
340 void FX_Random_GenerateBase(FX_LPDWORD pBuffer, int32_t iCount) 340 void FX_Random_GenerateBase(FX_DWORD* pBuffer, int32_t iCount)
341 { 341 {
342 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 342 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
343 SYSTEMTIME st1, st2; 343 SYSTEMTIME st1, st2;
344 ::GetSystemTime(&st1); 344 ::GetSystemTime(&st1);
345 do { 345 do {
346 ::GetSystemTime(&st2); 346 ::GetSystemTime(&st2);
347 } while (FXSYS_memcmp32(&st1, &st2, sizeof(SYSTEMTIME)) == 0); 347 } while (FXSYS_memcmp32(&st1, &st2, sizeof(SYSTEMTIME)) == 0);
348 FX_DWORD dwHash1 = FX_HashCode_String_GetA((FX_LPCSTR)&st1, sizeof(st1), TRU E); 348 FX_DWORD dwHash1 = FX_HashCode_String_GetA((const FX_CHAR*)&st1, sizeof(st1) , TRUE);
349 FX_DWORD dwHash2 = FX_HashCode_String_GetA((FX_LPCSTR)&st2, sizeof(st2), TRU E); 349 FX_DWORD dwHash2 = FX_HashCode_String_GetA((const FX_CHAR*)&st2, sizeof(st2) , TRUE);
350 ::srand((dwHash1 << 16) | (FX_DWORD)dwHash2); 350 ::srand((dwHash1 << 16) | (FX_DWORD)dwHash2);
351 #else 351 #else
352 time_t tmLast = time(NULL), tmCur; 352 time_t tmLast = time(NULL), tmCur;
353 while ((tmCur = time(NULL)) == tmLast); 353 while ((tmCur = time(NULL)) == tmLast);
354 ::srand((tmCur << 16) | (tmLast & 0xFFFF)); 354 ::srand((tmCur << 16) | (tmLast & 0xFFFF));
355 #endif 355 #endif
356 while (iCount -- > 0) { 356 while (iCount -- > 0) {
357 *pBuffer ++ = (FX_DWORD)((::rand() << 16) | (::rand() & 0xFFFF)); 357 *pBuffer ++ = (FX_DWORD)((::rand() << 16) | (::rand() & 0xFFFF));
358 } 358 }
359 } 359 }
360 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 360 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
361 FX_BOOL FX_GenerateCryptoRandom(FX_LPDWORD pBuffer, int32_t iCount) 361 FX_BOOL FX_GenerateCryptoRandom(FX_DWORD* pBuffer, int32_t iCount)
362 { 362 {
363 HCRYPTPROV hCP = NULL; 363 HCRYPTPROV hCP = NULL;
364 if (!::CryptAcquireContext(&hCP, NULL, NULL, PROV_RSA_FULL, 0) || hCP == NUL L) { 364 if (!::CryptAcquireContext(&hCP, NULL, NULL, PROV_RSA_FULL, 0) || hCP == NUL L) {
365 return FALSE; 365 return FALSE;
366 } 366 }
367 ::CryptGenRandom(hCP, iCount * sizeof(FX_DWORD), (FX_LPBYTE)pBuffer); 367 ::CryptGenRandom(hCP, iCount * sizeof(FX_DWORD), (uint8_t*)pBuffer);
368 ::CryptReleaseContext(hCP, 0); 368 ::CryptReleaseContext(hCP, 0);
369 return TRUE; 369 return TRUE;
370 } 370 }
371 #endif 371 #endif
372 void FX_Random_GenerateCrypto(FX_LPDWORD pBuffer, int32_t iCount) 372 void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount)
373 { 373 {
374 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 374 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
375 FX_GenerateCryptoRandom(pBuffer, iCount); 375 FX_GenerateCryptoRandom(pBuffer, iCount);
376 #else 376 #else
377 FX_Random_GenerateBase(pBuffer, iCount); 377 FX_Random_GenerateBase(pBuffer, iCount);
378 #endif 378 #endif
379 } 379 }
380 #ifdef __cplusplus 380 #ifdef __cplusplus
381 } 381 }
382 #endif 382 #endif
OLDNEW
« no previous file with comments | « core/src/fxcrt/fx_basic_wstring.cpp ('k') | core/src/fxcrt/fx_xml_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698