MCPcopy Create free account
hub / github.com/F-Stack/f-stack / deflateCopy

Function deflateCopy

freebsd/contrib/zlib/deflate.c:1105–1158  ·  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

1103 * doesn't have enough memory anyway to duplicate compression states).
1104 */
1105int ZEXPORT deflateCopy (dest, source)
1106 z_streamp dest;
1107 z_streamp source;
1108{
1109#ifdef MAXSEG_64K
1110 return Z_STREAM_ERROR;
1111#else
1112 deflate_state *ds;
1113 deflate_state *ss;
1114 ushf *overlay;
1115
1116
1117 if (deflateStateCheck(source) || dest == Z_NULL) {
1118 return Z_STREAM_ERROR;
1119 }
1120
1121 ss = source->state;
1122
1123 zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
1124
1125 ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
1126 if (ds == Z_NULL) return Z_MEM_ERROR;
1127 dest->state = (struct internal_state FAR *) ds;
1128 zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
1129 ds->strm = dest;
1130
1131 ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
1132 ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
1133 ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
1134 overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
1135 ds->pending_buf = (uchf *) overlay;
1136
1137 if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
1138 ds->pending_buf == Z_NULL) {
1139 deflateEnd (dest);
1140 return Z_MEM_ERROR;
1141 }
1142 /* following zmemcpy do not work for 16-bit MSDOS */
1143 zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
1144 zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
1145 zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
1146 zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
1147
1148 ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
1149 ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
1150 ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
1151
1152 ds->l_desc.dyn_tree = ds->dyn_ltree;
1153 ds->d_desc.dyn_tree = ds->dyn_dtree;
1154 ds->bl_desc.dyn_tree = ds->bl_tree;
1155
1156 return Z_OK;
1157#endif /* MAXSEG_64K */
1158}
1159
1160/* ===========================================================================
1161 * Read a new buffer from the current input stream, update the adler32

Callers 1

zstd_zlibwrapper.cFile · 0.85

Calls 3

deflateStateCheckFunction · 0.85
zmemcpyFunction · 0.85
deflateEndFunction · 0.85

Tested by

no test coverage detected