OLD | NEW |
---|---|
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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "core/fxcrt/extension.h" | 9 #include "core/fxcrt/extension.h" |
10 #include "core/fxcrt/include/fx_basic.h" | 10 #include "core/fxcrt/include/fx_basic.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 return (FX_BOOL)m_pFile->WritePos(buffer, size, offset); | 61 return (FX_BOOL)m_pFile->WritePos(buffer, size, offset); |
62 } | 62 } |
63 | 63 |
64 FX_BOOL CFX_CRTFileStream::Flush() { | 64 FX_BOOL CFX_CRTFileStream::Flush() { |
65 return m_pFile->Flush(); | 65 return m_pFile->Flush(); |
66 } | 66 } |
67 | 67 |
68 #ifdef PDF_ENABLE_XFA | 68 #ifdef PDF_ENABLE_XFA |
69 IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath) { | 69 IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath) { |
70 if (wsPath.GetLength() == 0) | 70 if (wsPath.GetLength() == 0) |
71 return NULL; | 71 return nullptr; |
72 | 72 |
73 CFX_CRTFileAccess* pFA = NULL; | 73 CFX_CRTFileAccess* pFA = nullptr; |
Tom Sepez
2016/06/02 20:09:49
nit combine
Lei Zhang
2016/06/07 07:33:23
Done.
| |
74 pFA = new CFX_CRTFileAccess; | 74 pFA = new CFX_CRTFileAccess; |
75 if (NULL == pFA) | 75 if (nullptr == pFA) |
Tom Sepez
2016/06/02 20:09:49
can't happen
Lei Zhang
2016/06/07 07:33:23
Done.
| |
76 return NULL; | 76 return nullptr; |
77 | 77 |
78 pFA->Init(wsPath); | 78 pFA->Init(wsPath); |
79 return pFA; | 79 return pFA; |
80 } | 80 } |
81 #endif // PDF_ENABLE_XFA | 81 #endif // PDF_ENABLE_XFA |
82 | 82 |
83 IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, uint32_t dwModes) { | 83 IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, uint32_t dwModes) { |
84 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); | 84 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); |
85 if (!pFA->Open(filename, dwModes)) | 85 if (!pFA->Open(filename, dwModes)) |
86 return nullptr; | 86 return nullptr; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 ::GetSystemTime(&st1); | 298 ::GetSystemTime(&st1); |
299 do { | 299 do { |
300 ::GetSystemTime(&st2); | 300 ::GetSystemTime(&st2); |
301 } while (FXSYS_memcmp(&st1, &st2, sizeof(SYSTEMTIME)) == 0); | 301 } while (FXSYS_memcmp(&st1, &st2, sizeof(SYSTEMTIME)) == 0); |
302 uint32_t dwHash1 = | 302 uint32_t dwHash1 = |
303 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)&st1, sizeof(st1)), true); | 303 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)&st1, sizeof(st1)), true); |
304 uint32_t dwHash2 = | 304 uint32_t dwHash2 = |
305 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)&st2, sizeof(st2)), true); | 305 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)&st2, sizeof(st2)), true); |
306 ::srand((dwHash1 << 16) | (uint32_t)dwHash2); | 306 ::srand((dwHash1 << 16) | (uint32_t)dwHash2); |
307 #else | 307 #else |
308 time_t tmLast = time(NULL); | 308 time_t tmLast = time(nullptr); |
309 time_t tmCur; | 309 time_t tmCur; |
310 while ((tmCur = time(NULL)) == tmLast) { | 310 while ((tmCur = time(nullptr)) == tmLast) { |
311 continue; | 311 continue; |
312 } | 312 } |
313 | 313 |
314 ::srand((tmCur << 16) | (tmLast & 0xFFFF)); | 314 ::srand((tmCur << 16) | (tmLast & 0xFFFF)); |
315 #endif | 315 #endif |
316 while (iCount-- > 0) { | 316 while (iCount-- > 0) { |
317 *pBuffer++ = (uint32_t)((::rand() << 16) | (::rand() & 0xFFFF)); | 317 *pBuffer++ = (uint32_t)((::rand() << 16) | (::rand() & 0xFFFF)); |
318 } | 318 } |
319 } | 319 } |
320 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 320 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
321 FX_BOOL FX_GenerateCryptoRandom(uint32_t* pBuffer, int32_t iCount) { | 321 FX_BOOL FX_GenerateCryptoRandom(uint32_t* pBuffer, int32_t iCount) { |
322 HCRYPTPROV hCP = NULL; | 322 HCRYPTPROV hCP = nullptr; |
323 if (!::CryptAcquireContext(&hCP, NULL, NULL, PROV_RSA_FULL, 0) || !hCP) { | 323 if (!::CryptAcquireContext(&hCP, nullptr, nullptr, PROV_RSA_FULL, 0) || |
324 !hCP) { | |
324 return FALSE; | 325 return FALSE; |
325 } | 326 } |
326 ::CryptGenRandom(hCP, iCount * sizeof(uint32_t), (uint8_t*)pBuffer); | 327 ::CryptGenRandom(hCP, iCount * sizeof(uint32_t), (uint8_t*)pBuffer); |
327 ::CryptReleaseContext(hCP, 0); | 328 ::CryptReleaseContext(hCP, 0); |
328 return TRUE; | 329 return TRUE; |
329 } | 330 } |
330 #endif | 331 #endif |
331 void FX_Random_GenerateCrypto(uint32_t* pBuffer, int32_t iCount) { | 332 void FX_Random_GenerateCrypto(uint32_t* pBuffer, int32_t iCount) { |
332 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 333 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
333 FX_GenerateCryptoRandom(pBuffer, iCount); | 334 FX_GenerateCryptoRandom(pBuffer, iCount); |
(...skipping 18 matching lines...) Expand all Loading... | |
352 b = ((const uint8_t*)pGUID)[i]; | 353 b = ((const uint8_t*)pGUID)[i]; |
353 *pBuf++ = gs_FX_pHexChars[b >> 4]; | 354 *pBuf++ = gs_FX_pHexChars[b >> 4]; |
354 *pBuf++ = gs_FX_pHexChars[b & 0x0F]; | 355 *pBuf++ = gs_FX_pHexChars[b & 0x0F]; |
355 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) { | 356 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) { |
356 *pBuf++ = L'-'; | 357 *pBuf++ = L'-'; |
357 } | 358 } |
358 } | 359 } |
359 bsStr.ReleaseBuffer(bSeparator ? 36 : 32); | 360 bsStr.ReleaseBuffer(bSeparator ? 36 : 32); |
360 } | 361 } |
361 #endif // PDF_ENABLE_XFA | 362 #endif // PDF_ENABLE_XFA |
OLD | NEW |