MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / deflateCopy

Function deflateCopy

extern/zlib/src/deflate.c:1282–1336  ·  view source on GitHub ↗

========================================================================= * Copy the source state to the destination state. * To simplify the source, this is not supported for 16-bit MSDOS (which * doesn't have enough memory anyway to duplicate compression states). */

Source from the content-addressed store, hash-verified

1280 * doesn't have enough memory anyway to duplicate compression states).
1281 */
1282int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) {
1283#ifdef MAXSEG_64K
1284 (void)dest;
1285 (void)source;
1286 return Z_STREAM_ERROR;
1287#else
1288 deflate_state *ds;
1289 deflate_state *ss;
1290
1291
1292 if (deflateStateCheck(source) || dest == Z_NULL) {
1293 return Z_STREAM_ERROR;
1294 }
1295
1296 ss = source->state;
1297
1298 zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
1299
1300 ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
1301 if (ds == Z_NULL) return Z_MEM_ERROR;
1302 dest->state = (struct internal_state FAR *) ds;
1303 zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
1304 ds->strm = dest;
1305
1306 ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
1307 ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
1308 ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
1309 ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, LIT_BUFS);
1310
1311 if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
1312 ds->pending_buf == Z_NULL) {
1313 deflateEnd (dest);
1314 return Z_MEM_ERROR;
1315 }
1316 /* following zmemcpy do not work for 16-bit MSDOS */
1317 zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
1318 zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
1319 zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
1320 zmemcpy(ds->pending_buf, ss->pending_buf, ds->lit_bufsize * LIT_BUFS);
1321
1322 ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
1323#ifdef LIT_MEM
1324 ds->d_buf = (ushf *)(ds->pending_buf + (ds->lit_bufsize << 1));
1325 ds->l_buf = ds->pending_buf + (ds->lit_bufsize << 2);
1326#else
1327 ds->sym_buf = ds->pending_buf + ds->lit_bufsize;
1328#endif
1329
1330 ds->l_desc.dyn_tree = ds->dyn_ltree;
1331 ds->d_desc.dyn_tree = ds->dyn_dtree;
1332 ds->bl_desc.dyn_tree = ds->bl_tree;
1333
1334 return Z_OK;
1335#endif /* MAXSEG_64K */
1336}
1337
1338#ifndef FASTEST
1339/* ===========================================================================

Callers

nothing calls this directly

Calls 3

deflateStateCheckFunction · 0.85
zmemcpyFunction · 0.85
deflateEndFunction · 0.85

Tested by

no test coverage detected