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