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 "../../include/fxcrt/fx_basic.h" | 7 #include "../../include/fxcrt/fx_basic.h" |
8 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_LPSTR buf); | 8 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_LPSTR buf); |
9 CFX_BinaryBuf::CFX_BinaryBuf() | 9 CFX_BinaryBuf::CFX_BinaryBuf() |
10 : m_AllocStep(0) | 10 : m_AllocStep(0) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } else { | 81 } else { |
82 alloc_step = m_AllocStep; | 82 alloc_step = m_AllocStep; |
83 } | 83 } |
84 new_size = (new_size + alloc_step - 1) / alloc_step * alloc_step; | 84 new_size = (new_size + alloc_step - 1) / alloc_step * alloc_step; |
85 FX_LPBYTE pNewBuffer = m_pBuffer; | 85 FX_LPBYTE pNewBuffer = m_pBuffer; |
86 if (pNewBuffer) { | 86 if (pNewBuffer) { |
87 pNewBuffer = FX_Realloc(FX_BYTE, m_pBuffer, new_size); | 87 pNewBuffer = FX_Realloc(FX_BYTE, m_pBuffer, new_size); |
88 } else { | 88 } else { |
89 pNewBuffer = FX_Alloc(FX_BYTE, new_size); | 89 pNewBuffer = FX_Alloc(FX_BYTE, new_size); |
90 } | 90 } |
91 if (pNewBuffer) { | 91 m_pBuffer = pNewBuffer; |
92 m_pBuffer = pNewBuffer; | 92 m_AllocSize = new_size; |
93 m_AllocSize = new_size; | |
94 } | |
95 } | 93 } |
96 void CFX_BinaryBuf::CopyData(const void* pStr, FX_STRSIZE size) | 94 void CFX_BinaryBuf::CopyData(const void* pStr, FX_STRSIZE size) |
97 { | 95 { |
98 if (size == 0) { | 96 if (size == 0) { |
99 m_DataSize = 0; | 97 m_DataSize = 0; |
100 return; | 98 return; |
101 } | 99 } |
102 if (m_AllocSize < size) { | 100 if (m_AllocSize < size) { |
103 ExpandBuf(size - m_DataSize); | 101 ExpandBuf(size - m_DataSize); |
104 } | 102 } |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 m_Length = 0; | 447 m_Length = 0; |
450 return bRet; | 448 return bRet; |
451 } | 449 } |
452 FX_INT32 IFX_BufferArchive::AppendBlock(const void* pBuf, size_t size) | 450 FX_INT32 IFX_BufferArchive::AppendBlock(const void* pBuf, size_t size) |
453 { | 451 { |
454 if (!pBuf || size < 1) { | 452 if (!pBuf || size < 1) { |
455 return 0; | 453 return 0; |
456 } | 454 } |
457 if (!m_pBuffer) { | 455 if (!m_pBuffer) { |
458 m_pBuffer = FX_Alloc(FX_BYTE, m_BufSize); | 456 m_pBuffer = FX_Alloc(FX_BYTE, m_BufSize); |
459 if (!m_pBuffer) { | |
460 return -1; | |
461 } | |
462 } | 457 } |
463 FX_LPBYTE buffer = (FX_LPBYTE)pBuf; | 458 FX_LPBYTE buffer = (FX_LPBYTE)pBuf; |
464 FX_STRSIZE temp_size = (FX_STRSIZE)size; | 459 FX_STRSIZE temp_size = (FX_STRSIZE)size; |
465 while (temp_size > 0) { | 460 while (temp_size > 0) { |
466 FX_STRSIZE buf_size = FX_MIN(m_BufSize - m_Length, (FX_STRSIZE)temp_size
); | 461 FX_STRSIZE buf_size = FX_MIN(m_BufSize - m_Length, (FX_STRSIZE)temp_size
); |
467 FXSYS_memcpy32(m_pBuffer + m_Length, buffer, buf_size); | 462 FXSYS_memcpy32(m_pBuffer + m_Length, buffer, buf_size); |
468 m_Length += buf_size; | 463 m_Length += buf_size; |
469 if (m_Length == m_BufSize) { | 464 if (m_Length == m_BufSize) { |
470 if (!Flush()) { | 465 if (!Flush()) { |
471 return -1; | 466 return -1; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 FX_BOOL CFX_FileBufferArchive::DoWork(const void* pBuf, size_t size) | 549 FX_BOOL CFX_FileBufferArchive::DoWork(const void* pBuf, size_t size) |
555 { | 550 { |
556 if (!m_pFile) { | 551 if (!m_pFile) { |
557 return FALSE; | 552 return FALSE; |
558 } | 553 } |
559 if (!pBuf || size < 1) { | 554 if (!pBuf || size < 1) { |
560 return TRUE; | 555 return TRUE; |
561 } | 556 } |
562 return m_pFile->WriteBlock(pBuf, size); | 557 return m_pFile->WriteBlock(pBuf, size); |
563 } | 558 } |
OLD | NEW |