MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / deflateCopy

Function deflateCopy

ZLib/deflate.c:1014–1067  ·  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). */

(dest, source)

Source from the content-addressed store, hash-verified

1012 * doesn't have enough memory anyway to duplicate compression states).
1013 */
1014int ZEXPORT deflateCopy (dest, source)
1015 z_streamp dest;
1016 z_streamp source;
1017{
1018#ifdef MAXSEG_64K
1019 return Z_STREAM_ERROR;
1020#else
1021 deflate_state *ds;
1022 deflate_state *ss;
1023 ushf *overlay;
1024
1025
1026 if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
1027 return Z_STREAM_ERROR;
1028 }
1029
1030 ss = source->state;
1031
1032 zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
1033
1034 ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
1035 if (ds == Z_NULL) return Z_MEM_ERROR;
1036 dest->state = (struct internal_state FAR *) ds;
1037 zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
1038 ds->strm = dest;
1039
1040 ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
1041 ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
1042 ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
1043 overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
1044 ds->pending_buf = (uchf *) overlay;
1045
1046 if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
1047 ds->pending_buf == Z_NULL) {
1048 deflateEnd (dest);
1049 return Z_MEM_ERROR;
1050 }
1051 /* following zmemcpy do not work for 16-bit MSDOS */
1052 zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
1053 zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
1054 zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
1055 zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
1056
1057 ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
1058 ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
1059 ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
1060
1061 ds->l_desc.dyn_tree = ds->dyn_ltree;
1062 ds->d_desc.dyn_tree = ds->dyn_dtree;
1063 ds->bl_desc.dyn_tree = ds->bl_tree;
1064
1065 return Z_OK;
1066#endif /* MAXSEG_64K */
1067}
1068
1069/* ===========================================================================
1070 * Read a new buffer from the current input stream, update the adler32

Callers

nothing calls this directly

Calls 2

zmemcpyFunction · 0.85
deflateEndFunction · 0.85

Tested by

no test coverage detected