aboutsummaryrefslogtreecommitdiff
path: root/libctf/ctf-create.c
diff options
context:
space:
mode:
Diffstat (limited to 'libctf/ctf-create.c')
-rw-r--r--libctf/ctf-create.c52
1 files changed, 38 insertions, 14 deletions
diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index 24ea114..cef2351 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -294,6 +294,8 @@ ctf_update (ctf_file_t *fp)
hdrp = (ctf_header_t *) buf;
if ((fp->ctf_flags & LCTF_CHILD) && (fp->ctf_parname != NULL))
ctf_str_add_ref (fp, fp->ctf_parname, &hdrp->cth_parname);
+ if (fp->ctf_cuname != NULL)
+ ctf_str_add_ref (fp, fp->ctf_cuname, &hdrp->cth_cuname);
/* Work over the variable list, translating everything into ctf_varent_t's and
prepping the string table. */
@@ -443,7 +445,8 @@ ctf_update (ctf_file_t *fp)
nfp->ctf_refcnt = fp->ctf_refcnt;
nfp->ctf_flags |= fp->ctf_flags & ~LCTF_DIRTY;
- nfp->ctf_data.cts_data = NULL; /* Force ctf_free() on close. */
+ if (nfp->ctf_dynbase == NULL)
+ nfp->ctf_dynbase = buf; /* Make sure buf is freed on close. */
nfp->ctf_dthash = fp->ctf_dthash;
nfp->ctf_dtdefs = fp->ctf_dtdefs;
nfp->ctf_dtbyname = fp->ctf_dtbyname;
@@ -1919,15 +1922,26 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
return dst_type;
}
-/* Write the compressed CTF data stream to the specified gzFile descriptor.
- This is useful for saving the results of dynamic CTF containers. */
+/* Write the compressed CTF data stream to the specified gzFile descriptor. */
int
ctf_gzwrite (ctf_file_t *fp, gzFile fd)
{
- const unsigned char *buf = fp->ctf_base;
- ssize_t resid = fp->ctf_size;
+ const unsigned char *buf;
+ ssize_t resid;
ssize_t len;
+ resid = sizeof (ctf_header_t);
+ buf = (unsigned char *) fp->ctf_header;
+ while (resid != 0)
+ {
+ if ((len = gzwrite (fd, buf, resid)) <= 0)
+ return (ctf_set_errno (fp, errno));
+ resid -= len;
+ buf += len;
+ }
+
+ resid = fp->ctf_size;
+ buf = fp->ctf_buf;
while (resid != 0)
{
if ((len = gzwrite (fd, buf, resid)) <= 0)
@@ -1950,12 +1964,12 @@ ctf_compress_write (ctf_file_t *fp, int fd)
ctf_header_t *hp = &h;
ssize_t header_len = sizeof (ctf_header_t);
ssize_t compress_len;
- size_t max_compress_len = compressBound (fp->ctf_size - header_len);
+ size_t max_compress_len = compressBound (fp->ctf_size);
ssize_t len;
int rc;
int err = 0;
- memcpy (hp, fp->ctf_base, header_len);
+ memcpy (hp, fp->ctf_header, header_len);
hp->cth_flags |= CTF_F_COMPRESS;
if ((buf = ctf_alloc (max_compress_len)) == NULL)
@@ -1963,8 +1977,7 @@ ctf_compress_write (ctf_file_t *fp, int fd)
compress_len = max_compress_len;
if ((rc = compress (buf, (uLongf *) &compress_len,
- fp->ctf_base + header_len,
- fp->ctf_size - header_len)) != Z_OK)
+ fp->ctf_buf, fp->ctf_size)) != Z_OK)
{
ctf_dprintf ("zlib deflate err: %s\n", zError (rc));
err = ctf_set_errno (fp, ECTF_COMPRESS);
@@ -2000,18 +2013,29 @@ ret:
return err;
}
-/* Write the uncompressed CTF data stream to the specified file descriptor.
- This is useful for saving the results of dynamic CTF containers. */
+/* Write the uncompressed CTF data stream to the specified file descriptor. */
int
ctf_write (ctf_file_t *fp, int fd)
{
- const unsigned char *buf = fp->ctf_base;
- ssize_t resid = fp->ctf_size;
+ const unsigned char *buf;
+ ssize_t resid;
ssize_t len;
+ resid = sizeof (ctf_header_t);
+ buf = (unsigned char *) fp->ctf_header;
+ while (resid != 0)
+ {
+ if ((len = write (fd, buf, resid)) <= 0)
+ return (ctf_set_errno (fp, errno));
+ resid -= len;
+ buf += len;
+ }
+
+ resid = fp->ctf_size;
+ buf = fp->ctf_buf;
while (resid != 0)
{
- if ((len = write (fd, buf, resid)) < 0)
+ if ((len = write (fd, buf, resid)) <= 0)
return (ctf_set_errno (fp, errno));
resid -= len;
buf += len;