diff options
-rw-r--r-- | lib/rpmtd.c | 26 | ||||
-rw-r--r-- | lib/rpmtd.h | 10 |
2 files changed, 36 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; +} diff --git a/lib/rpmtd.h b/lib/rpmtd.h index 1a441e4cb..c5e4a8fc3 100644 --- a/lib/rpmtd.h +++ b/lib/rpmtd.h @@ -179,4 +179,14 @@ int rpmtdFromArgv(rpmtd td, rpmTag tag, ARGV_t argv); */ int rpmtdFromArgi(rpmtd td, rpmTag tag, ARGI_t argi); +/* \ingroup rpmtd + * Perform deep copy of container. + * Create a modifiable copy of tag data container (on string arrays each + * string is separately allocated) + * @todo Only string arrays types are supported currently + * @param td Container to copy + * @return New container or NULL on error + */ +rpmtd rpmtdDup(rpmtd td); + #endif /* _RPMTD_H */ |