Lines Matching defs:czd
140 ctf_zdata_init(ctf_zdata_t *czd, ctf_file_t *fp)
144 bzero(czd, sizeof (ctf_zdata_t));
146 czd->czd_allocsz = fp->ctf_size;
147 czd->czd_buf = ctf_data_alloc(czd->czd_allocsz);
148 if (czd->czd_buf == MAP_FAILED)
151 bcopy(fp->ctf_base, czd->czd_buf, sizeof (ctf_header_t));
152 czd->czd_ctfp = fp;
153 cthp = czd->czd_buf;
155 czd->czd_next = (void *)((uintptr_t)czd->czd_buf +
158 if (zlib.z_initcomp(&czd->czd_zstr, Z_BEST_COMPRESSION,
166 ctf_zdata_grow(ctf_zdata_t *czd)
172 off = (uintptr_t)czd->czd_next - (uintptr_t)czd->czd_buf;
173 newsz = czd->czd_allocsz + CTF_COMPRESS_CHUNK;
176 return (ctf_set_errno(czd->czd_ctfp, ENOMEM));
179 bcopy(czd->czd_buf, ndata, off);
180 ctf_data_free(czd->czd_buf, czd->czd_allocsz);
181 czd->czd_allocsz = newsz;
182 czd->czd_buf = ndata;
183 czd->czd_next = (void *)((uintptr_t)ndata + off);
185 czd->czd_zstr.next_out = (Bytef *)czd->czd_next;
186 czd->czd_zstr.avail_out = CTF_COMPRESS_CHUNK;
191 ctf_zdata_compress_buffer(ctf_zdata_t *czd, const void *buf, size_t bufsize)
195 czd->czd_zstr.next_out = czd->czd_next;
196 czd->czd_zstr.avail_out = czd->czd_allocsz -
197 ((uintptr_t)czd->czd_next - (uintptr_t)czd->czd_buf);
198 czd->czd_zstr.next_in = (Bytef *)buf;
199 czd->czd_zstr.avail_in = bufsize;
201 while (czd->czd_zstr.avail_in != 0) {
202 if (czd->czd_zstr.avail_out == 0) {
203 czd->czd_next = czd->czd_zstr.next_out;
204 if ((err = ctf_zdata_grow(czd)) != 0) {
209 if ((err = zlib.z_compress(&czd->czd_zstr, Z_NO_FLUSH)) != Z_OK)
210 return (ctf_set_errno(czd->czd_ctfp, ECTF_ZLIB));
212 czd->czd_next = czd->czd_zstr.next_out;
218 ctf_zdata_flush(ctf_zdata_t *czd, boolean_t finish)
225 if (czd->czd_zstr.avail_out == 0) {
226 czd->czd_next = czd->czd_zstr.next_out;
227 if ((err = ctf_zdata_grow(czd)) != 0) {
232 err = zlib.z_compress(&czd->czd_zstr, flag);
237 return (ctf_set_errno(czd->czd_ctfp, ECTF_ZLIB));
241 czd->czd_next = czd->czd_zstr.next_out;
247 ctf_zdata_end(ctf_zdata_t *czd)
251 if ((ret = ctf_zdata_flush(czd, B_TRUE)) != 0)
254 if ((ret = zlib.z_finicomp(&czd->czd_zstr)) != 0)
255 return (ctf_set_errno(czd->czd_ctfp, ECTF_ZLIB));
261 ctf_zdata_cleanup(ctf_zdata_t *czd)
263 ctf_data_free(czd->czd_buf, czd->czd_allocsz);
264 (void) zlib.z_finicomp(&czd->czd_zstr);
279 ctf_zdata_t czd;
282 if ((err = ctf_zdata_init(&czd, fp)) != 0)
285 if ((err = ctf_zdata_compress_buffer(&czd, fp->ctf_buf,
287 ctf_zdata_cleanup(&czd);
291 if ((err = ctf_zdata_flush(&czd, B_FALSE)) != 0) {
292 ctf_zdata_cleanup(&czd);
296 if ((err = ctf_zdata_compress_buffer(&czd,
298 ctf_zdata_cleanup(&czd);
302 if ((err = ctf_zdata_end(&czd)) != 0) {
303 ctf_zdata_cleanup(&czd);
307 *buf = czd.czd_buf;
308 *allocsz = czd.czd_allocsz;
309 *elfsize = (uintptr_t)czd.czd_next - (uintptr_t)czd.czd_buf;