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 "core/include/fxcrt/fx_basic.h" | 7 #include "core/include/fxcrt/fx_basic.h" |
8 #include "core/include/fxcrt/fx_ext.h" | 8 #include "core/include/fxcrt/fx_ext.h" |
9 #include "extension.h" | 9 #include "extension.h" |
10 | 10 |
11 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 11 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
12 #include <wincrypt.h> | 12 #include <wincrypt.h> |
13 #else | 13 #else |
14 #include <ctime> | 14 #include <ctime> |
15 #endif | 15 #endif |
16 | 16 |
| 17 CFX_CRTFileStream::CFX_CRTFileStream(IFXCRT_FileAccess* pFA) |
| 18 : m_pFile(pFA), m_dwCount(1) {} |
| 19 |
| 20 CFX_CRTFileStream::~CFX_CRTFileStream() { |
| 21 if (m_pFile) { |
| 22 m_pFile->Release(); |
| 23 } |
| 24 } |
| 25 |
| 26 IFX_FileStream* CFX_CRTFileStream::Retain() { |
| 27 m_dwCount++; |
| 28 return this; |
| 29 } |
| 30 |
| 31 void CFX_CRTFileStream::Release() { |
| 32 FX_DWORD nCount = --m_dwCount; |
| 33 if (!nCount) { |
| 34 delete this; |
| 35 } |
| 36 } |
| 37 |
| 38 FX_FILESIZE CFX_CRTFileStream::GetSize() { |
| 39 return m_pFile->GetSize(); |
| 40 } |
| 41 |
| 42 FX_BOOL CFX_CRTFileStream::IsEOF() { |
| 43 return GetPosition() >= GetSize(); |
| 44 } |
| 45 |
| 46 FX_FILESIZE CFX_CRTFileStream::GetPosition() { |
| 47 return m_pFile->GetPosition(); |
| 48 } |
| 49 |
| 50 FX_BOOL CFX_CRTFileStream::ReadBlock(void* buffer, |
| 51 FX_FILESIZE offset, |
| 52 size_t size) { |
| 53 return (FX_BOOL)m_pFile->ReadPos(buffer, size, offset); |
| 54 } |
| 55 |
| 56 size_t CFX_CRTFileStream::ReadBlock(void* buffer, size_t size) { |
| 57 return m_pFile->Read(buffer, size); |
| 58 } |
| 59 |
| 60 FX_BOOL CFX_CRTFileStream::WriteBlock(const void* buffer, |
| 61 FX_FILESIZE offset, |
| 62 size_t size) { |
| 63 return (FX_BOOL)m_pFile->WritePos(buffer, size, offset); |
| 64 } |
| 65 |
| 66 FX_BOOL CFX_CRTFileStream::Flush() { |
| 67 return m_pFile->Flush(); |
| 68 } |
| 69 |
17 IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, FX_DWORD dwModes) { | 70 IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, FX_DWORD dwModes) { |
18 IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(); | 71 IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(); |
19 if (!pFA) { | 72 if (!pFA) { |
20 return NULL; | 73 return NULL; |
21 } | 74 } |
22 if (!pFA->Open(filename, dwModes)) { | 75 if (!pFA->Open(filename, dwModes)) { |
23 pFA->Release(); | 76 pFA->Release(); |
24 return NULL; | 77 return NULL; |
25 } | 78 } |
26 return new CFX_CRTFileStream(pFA); | 79 return new CFX_CRTFileStream(pFA); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 return TRUE; | 336 return TRUE; |
284 } | 337 } |
285 #endif | 338 #endif |
286 void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount) { | 339 void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount) { |
287 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 340 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
288 FX_GenerateCryptoRandom(pBuffer, iCount); | 341 FX_GenerateCryptoRandom(pBuffer, iCount); |
289 #else | 342 #else |
290 FX_Random_GenerateBase(pBuffer, iCount); | 343 FX_Random_GenerateBase(pBuffer, iCount); |
291 #endif | 344 #endif |
292 } | 345 } |
OLD | NEW |