summaryrefslogtreecommitdiff
path: root/lib/rpmtd.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2008-05-21 09:22:38 +0300
committerPanu Matilainen <pmatilai@redhat.com>2008-05-21 12:04:51 +0300
commitce70ac871764ec835d5c83b3115d3a7236196838 (patch)
treea8677fae791485f84fcaa07ff54cfec6238d076a /lib/rpmtd.c
parent34151a9e35122d90bdc1863dc5dc5e1fec786afe (diff)
downloadlibrpm-tizen-ce70ac871764ec835d5c83b3115d3a7236196838.tar.gz
librpm-tizen-ce70ac871764ec835d5c83b3115d3a7236196838.tar.bz2
librpm-tizen-ce70ac871764ec835d5c83b3115d3a7236196838.zip
Add rpmtdDup() method for deep copying of tag containers
Diffstat (limited to 'lib/rpmtd.c')
-rw-r--r--lib/rpmtd.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/rpmtd.c b/lib/rpmtd.c
index 998dd321f..89482335c 100644
--- a/lib/rpmtd.c
+++ b/lib/rpmtd.c
@@ -205,3 +205,29 @@ int rpmtdFromArgi(rpmtd td, rpmTag tag, ARGI_t argi)
td->data = argiData(argi);
return 1;
}
+
+rpmtd rpmtdDup(rpmtd td)
+{
+ rpmtd newtd = NULL;
+ char **data = NULL;
+ int i;
+
+ assert(td != NULL);
+ /* TODO: permit other types too */
+ if (td->type != RPM_STRING_ARRAY_TYPE && td->type != RPM_I18NSTRING_TYPE) {
+ return NULL;
+ }
+
+ /* deep-copy container and data, drop immutable flag */
+ newtd = rpmtdNew();
+ memcpy(newtd, td, sizeof(*td));
+ newtd->flags &= ~(RPMTD_IMMUTABLE);
+
+ newtd->flags |= (RPMTD_ALLOCED | RPMTD_PTR_ALLOCED);
+ newtd->data = data = xmalloc(td->count * sizeof(*data));
+ while ((i = rpmtdNext(td)) >= 0) {
+ data[i] = xstrdup(rpmtdGetString(td));
+ }
+
+ return newtd;
+}