Add rpmtdDup() method for deep copying of tag containers
This commit is contained in:
parent
34151a9e35
commit
ce70ac8717
26
lib/rpmtd.c
26
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;
|
||||
}
|
||||
|
|
10
lib/rpmtd.h
10
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 */
|
||||
|
|
Loading…
Reference in New Issue