Changeset 21814 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Jul 27, 2009 2:45:34 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/zip.cpp
r21800 r21814 38 38 #define RTZIP_USE_LZF 1 39 39 #define RTZIP_LZF_BLOCK_BY_BLOCK 40 //#define RTZIP_USE_LZJB 1 41 42 /** @todo lzjb? LZO? QuickLZ? Others? */ 40 43 41 44 … … 1673 1676 RT_EXPORT_SYMBOL(RTZipDecompDestroy); 1674 1677 1678 1679 RTDECL(int) RTZipBlockCompress(RTZIPTYPE enmType, RTZIPLEVEL enmLevel, uint32_t fFlags, 1680 void const *pvSrc, size_t cbSrc, 1681 void *pvDst, size_t cbDst, size_t *pcbDstActual) RT_NO_THROW 1682 { 1683 /* input validation - the crash and burn approach as speed is essential here. */ 1684 Assert(enmLevel <= RTZIPLEVEL_MAX && enmLevel >= RTZIPLEVEL_STORE); 1685 Assert(!fFlags); 1686 1687 /* 1688 * Deal with flags involving prefixes. 1689 */ 1690 /** @todo later: type and/or compressed length prefix. */ 1691 1692 /* 1693 * The type specific part. 1694 */ 1695 switch (enmType) 1696 { 1697 case RTZIPTYPE_LZF: 1698 { 1699 #ifdef RTZIP_USE_LZF 1700 unsigned cbDstActual = lzf_compress(pvSrc, cbSrc, pvDst, cbDst); 1701 if (RT_UNLIKELY(cbDstActual < 1)) 1702 return VERR_BUFFER_OVERFLOW; 1703 *pcbDstActual = cbDstActual; 1704 break; 1705 #else 1706 return VERR_NOT_SUPPORTED; 1707 #endif 1708 } 1709 1710 case RTZIPTYPE_STORE: 1711 { 1712 if (cbDst < cbSrc) 1713 return VERR_BUFFER_OVERFLOW; 1714 memcpy(pvDst, pvSrc, cbSrc); 1715 *pcbDstActual = cbSrc; 1716 break; 1717 } 1718 1719 case RTZIPTYPE_LZJB: 1720 { 1721 #ifdef RTZIP_USE_LZJB 1722 AssertReturn(cbDst >= cbSrc, VERR_BUFFER_OVERFLOW); 1723 size_t cbDstActual = lzjb_compress((void *)pvSrc, (uint8_t *)pvDst + 1, cbSrc, cbSrc, 0 /*??*/); 1724 if (cbDst == cbSrc) 1725 *(uint8_t *)pvDst = 0; 1726 else 1727 *(uint8_t *)pvDst = 1; 1728 *pcbDstActual = cbDstActual + 1; 1729 break; 1730 #else 1731 return VERR_NOT_SUPPORTED; 1732 #endif 1733 } 1734 1735 case RTZIPTYPE_ZLIB: 1736 case RTZIPTYPE_BZLIB: 1737 return VERR_NOT_SUPPORTED; 1738 1739 default: 1740 AssertMsgFailed(("%d\n", enmType)); 1741 return VERR_INVALID_PARAMETER; 1742 } 1743 1744 return VINF_SUCCESS; 1745 } 1746 RT_EXPORT_SYMBOL(RTZipBlockCompress); 1747 1748 1749 RTDECL(int) RTZipBlockDecompress(RTZIPTYPE enmType, uint32_t fFlags, 1750 void const *pvSrc, size_t cbSrc, size_t *pcbSrcActual, 1751 void *pvDst, size_t cbDst, size_t *pcbDstActual) RT_NO_THROW 1752 { 1753 /* input validation - the crash and burn approach as speed is essential here. */ 1754 Assert(!fFlags); 1755 1756 /* 1757 * Deal with flags involving prefixes. 1758 */ 1759 /** @todo later: type and/or compressed length prefix. */ 1760 1761 /* 1762 * The type specific part. 1763 */ 1764 switch (enmType) 1765 { 1766 case RTZIPTYPE_LZF: 1767 { 1768 #ifdef RTZIP_USE_LZF 1769 unsigned cbDstActual = lzf_decompress(pvSrc, cbSrc, pvDst, cbDst); 1770 if (RT_UNLIKELY(cbDstActual < 1)) 1771 { 1772 if (errno == E2BIG) 1773 return VERR_BUFFER_OVERFLOW; 1774 Assert(errno == EINVAL); 1775 return VERR_GENERAL_FAILURE; 1776 } 1777 if (pcbDstActual) 1778 *pcbDstActual = cbDstActual; 1779 if (pcbSrcActual) 1780 *pcbSrcActual = cbSrc; 1781 break; 1782 #else 1783 return VERR_NOT_SUPPORTED; 1784 #endif 1785 } 1786 1787 case RTZIPTYPE_STORE: 1788 { 1789 if (cbDst < cbSrc) 1790 return VERR_BUFFER_OVERFLOW; 1791 memcpy(pvDst, pvSrc, cbSrc); 1792 if (pcbDstActual) 1793 *pcbDstActual = cbSrc; 1794 if (pcbSrcActual) 1795 *pcbSrcActual = cbSrc; 1796 break; 1797 } 1798 1799 case RTZIPTYPE_LZJB: 1800 { 1801 #ifdef RTZIP_USE_LZJB 1802 if (*(uint8_t *)pvSrc == 1) 1803 { 1804 int rc = lzjb_decompress((uint8_t *)pvSrc + 1, pvDst, cbSrc - 1, cbDst, 0 /*??*/); 1805 if (RT_UNLIKELY(rc != 0)) 1806 return VERR_BUFFER_OVERFLOW; 1807 if (pcbDstActual) 1808 *pcbDstActual = cbDst; 1809 } 1810 else 1811 { 1812 AssertReturn(cbDst >= cbSrc + 1, VERR_BUFFER_OVERFLOW); 1813 memcpy(pvDst, (uint8_t *)pvSrc + 1, cbSrc); 1814 } 1815 if (pcbSrcActual) 1816 *pcbSrcActual = cbSrc; 1817 break; 1818 #else 1819 return VERR_NOT_SUPPORTED; 1820 #endif 1821 } 1822 1823 case RTZIPTYPE_ZLIB: 1824 case RTZIPTYPE_BZLIB: 1825 case RTZIPTYPE_LZO: 1826 return VERR_NOT_SUPPORTED; 1827 1828 default: 1829 AssertMsgFailed(("%d\n", enmType)); 1830 return VERR_INVALID_PARAMETER; 1831 } 1832 return VINF_SUCCESS; 1833 } 1834 RT_EXPORT_SYMBOL(RTZipBlockDecompress); 1835
Note:
See TracChangeset
for help on using the changeset viewer.