Changeset 21800 in vbox
- Timestamp:
- Jul 26, 2009 3:51:06 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/zip.cpp
r21337 r21800 5 5 6 6 /* 7 * Copyright (C) 2006-200 7Sun Microsystems, Inc.7 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 37 37 //#define RTZIP_USE_BZLIB 1 38 38 #define RTZIP_USE_LZF 1 39 #define RTZIP_LZF_BLOCK_BY_BLOCK 39 40 40 41 … … 224 225 struct 225 226 { 227 # ifndef RTZIP_LZF_BLOCK_BY_BLOCK 226 228 /** Current input buffer postition. */ 227 229 uint8_t *pbInput; 228 230 /** The number of bytes left in the input buffer. */ 229 231 size_t cbInput; 232 # endif 230 233 /** The spill buffer. 231 234 * LZF is a block based compressor and not a stream compressor. So, … … 1080 1083 * not possible we'll use the spill buffer. 1081 1084 */ 1085 # ifdef RTZIP_LZF_BLOCK_BY_BLOCK 1086 size_t cbWritten = 0; 1087 while (cbBuf > 0) 1088 { 1089 /* 1090 * Anything in the spill buffer? 1091 */ 1092 if (pZip->u.LZF.cbSpill > 0) 1093 { 1094 unsigned cb = (unsigned)RT_MIN(pZip->u.LZF.cbSpill, cbBuf); 1095 memcpy(pvBuf, pZip->u.LZF.pbSpill, cb); 1096 pZip->u.LZF.pbSpill += cb; 1097 pZip->u.LZF.cbSpill -= cb; 1098 cbWritten += cb; 1099 cbBuf -= cb; 1100 if (!cbBuf) 1101 break; 1102 pvBuf = (uint8_t *)pvBuf + cb; 1103 } 1104 1105 /* 1106 * We always read and work one block at a time. 1107 */ 1108 RTZIPLZFHDR Hdr; 1109 int rc = pZip->pfnIn(pZip->pvUser, &Hdr, sizeof(Hdr), NULL); 1110 if (RT_FAILURE(rc)) 1111 return rc; 1112 if (!rtZipLZFValidHeader(&Hdr)) 1113 return VERR_GENERAL_FAILURE; /** @todo Get better error codes for RTZip! */ 1114 if (Hdr.cbData > 0) 1115 { 1116 rc = pZip->pfnIn(pZip->pvUser, &pZip->abBuffer[0], Hdr.cbData, NULL); 1117 if (RT_FAILURE(rc)) 1118 return rc; 1119 } 1120 1121 /* 1122 * Does the uncompressed data fit into the supplied buffer? 1123 * If so we uncompress it directly into the user buffer, else we'll have to use the spill buffer. 1124 */ 1125 unsigned cbUncompressed = Hdr.cbUncompressed; 1126 if (cbUncompressed <= cbBuf) 1127 { 1128 unsigned cbOutput = lzf_decompress(&pZip->abBuffer[0], Hdr.cbData, pvBuf, cbUncompressed); 1129 if (cbOutput != cbUncompressed) 1130 { 1131 AssertMsgFailed(("Decompression error, errno=%d. cbOutput=%#x cbUncompressed=%#x\n", 1132 errno, cbOutput, cbUncompressed)); 1133 return VERR_GENERAL_FAILURE; /** @todo Get better error codes for RTZip! */ 1134 } 1135 cbBuf -= cbUncompressed; 1136 pvBuf = (uint8_t *)pvBuf + cbUncompressed; 1137 cbWritten += cbUncompressed; 1138 } 1139 else 1140 { 1141 unsigned cbOutput = lzf_decompress(&pZip->abBuffer[0], Hdr.cbData, pZip->u.LZF.abSpill, cbUncompressed); 1142 if (cbOutput != cbUncompressed) 1143 { 1144 AssertMsgFailed(("Decompression error, errno=%d. cbOutput=%#x cbUncompressed=%#x\n", 1145 errno, cbOutput, cbUncompressed)); 1146 return VERR_GENERAL_FAILURE; /** @todo Get better error codes for RTZip! */ 1147 } 1148 pZip->u.LZF.pbSpill = &pZip->u.LZF.abSpill[0]; 1149 pZip->u.LZF.cbSpill = cbUncompressed; 1150 } 1151 } 1152 1153 if (pcbWritten) 1154 *pcbWritten = cbWritten; 1155 # else /* !RTZIP_LZF_BLOCK_BY_BLOCK */ 1082 1156 while (cbBuf > 0) 1083 1157 { … … 1200 1274 *pcbWritten += cbUncompressed; 1201 1275 } 1202 1276 # endif /* !RTZIP_LZF_BLOCK_BY_BLOCK */ 1203 1277 return VINF_SUCCESS; 1204 1278 } … … 1224 1298 pZip->pfnDestroy = rtZipLZFDecompDestroy; 1225 1299 1300 # ifndef RTZIP_LZF_BLOCK_BY_BLOCK 1226 1301 pZip->u.LZF.pbInput = NULL; 1227 1302 pZip->u.LZF.cbInput = 0; 1303 # endif 1228 1304 pZip->u.LZF.cbSpill = 0; 1229 1305 pZip->u.LZF.pbSpill = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.