| 5486 | #define MZ_WRITE_LE32(p, v) mz_write_le32((mz_uint8 *)(p), (mz_uint32)(v)) |
| 5487 | |
| 5488 | mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size) { |
| 5489 | if ((!pZip) || (pZip->m_pState) || (!pZip->m_pWrite) || |
| 5490 | (pZip->m_zip_mode != MZ_ZIP_MODE_INVALID)) |
| 5491 | return MZ_FALSE; |
| 5492 | |
| 5493 | if (pZip->m_file_offset_alignment) { |
| 5494 | // Ensure user specified file offset alignment is a power of 2. |
| 5495 | if (pZip->m_file_offset_alignment & (pZip->m_file_offset_alignment - 1)) |
| 5496 | return MZ_FALSE; |
| 5497 | } |
| 5498 | |
| 5499 | if (!pZip->m_pAlloc) |
| 5500 | pZip->m_pAlloc = def_alloc_func; |
| 5501 | if (!pZip->m_pFree) |
| 5502 | pZip->m_pFree = def_free_func; |
| 5503 | if (!pZip->m_pRealloc) |
| 5504 | pZip->m_pRealloc = def_realloc_func; |
| 5505 | |
| 5506 | pZip->m_zip_mode = MZ_ZIP_MODE_WRITING; |
| 5507 | pZip->m_archive_size = existing_size; |
| 5508 | pZip->m_central_directory_file_ofs = 0; |
| 5509 | pZip->m_total_files = 0; |
| 5510 | |
| 5511 | if (NULL == (pZip->m_pState = (mz_zip_internal_state *)pZip->m_pAlloc( |
| 5512 | pZip->m_pAlloc_opaque, 1, sizeof(mz_zip_internal_state)))) |
| 5513 | return MZ_FALSE; |
| 5514 | memset(pZip->m_pState, 0, sizeof(mz_zip_internal_state)); |
| 5515 | MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir, |
| 5516 | sizeof(mz_uint8)); |
| 5517 | MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir_offsets, |
| 5518 | sizeof(mz_uint32)); |
| 5519 | MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_sorted_central_dir_offsets, |
| 5520 | sizeof(mz_uint32)); |
| 5521 | return MZ_TRUE; |
| 5522 | } |
| 5523 | |
| 5524 | static size_t mz_zip_heap_write_func(void *pOpaque, mz_uint64 file_ofs, |
| 5525 | const void *pBuf, size_t n) { |
no outgoing calls
no test coverage detected