From cff6a5d9918f41fb920387e5dbbc78a52bfbd2c1 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 24 Oct 2014 10:02:19 +0300 Subject: [PATCH] Remember data (allocation) size of non-extension data from headerGet() - Add size member to rpmtd_s and accessor function to get it. For now only works for data marked with RPMTD_IMMUTABLE. - This is redundant for BIN type, but especially for string types this info is impossible to get without walking the entire data. --- lib/header.c | 1 + lib/rpmtd.c | 5 +++++ lib/rpmtd.h | 9 +++++++++ 3 files changed, 15 insertions(+) diff --git a/lib/header.c b/lib/header.c index f78ba788f..8a0f4beac 100644 --- a/lib/header.c +++ b/lib/header.c @@ -1176,6 +1176,7 @@ static int copyTdEntry(const indexEntry entry, rpmtd td, headerGetFlags flags) } td->type = entry->info.type; td->count = count; + td->size = entry->length; if (td->data && entry->data != td->data) { td->flags |= RPMTD_ALLOCED; diff --git a/lib/rpmtd.c b/lib/rpmtd.c index 550d733ab..b933c8863 100644 --- a/lib/rpmtd.c +++ b/lib/rpmtd.c @@ -57,6 +57,11 @@ rpm_count_t rpmtdCount(rpmtd td) return (td->type == RPM_BIN_TYPE) ? 1 : td->count; } +rpm_count_t rpmtdSize(rpmtd td) +{ + return (td != NULL) ? td->size : 0; +} + rpmTagVal rpmtdTag(rpmtd td) { assert(td != NULL); diff --git a/lib/rpmtd.h b/lib/rpmtd.h index a8f0b7121..76f1ca56c 100644 --- a/lib/rpmtd.h +++ b/lib/rpmtd.h @@ -30,6 +30,7 @@ struct rpmtd_s { rpm_data_t data; /* pointer to actual data */ rpmtdFlags flags; /* flags on memory allocation etc */ int ix; /* iteration index */ + rpm_count_t size; /* size of data (only works for RPMTD_IMMUTABLE atm) */ }; /** \ingroup rpmtd @@ -66,6 +67,14 @@ void rpmtdFreeData(rpmtd td); */ rpm_count_t rpmtdCount(rpmtd td); +/** \ingroup rpmtd + * Retrieve container data size (eg required for allocation). + * Note this currently only works for RPMTD_IMMUTABLE data. + * @param td Tag data container + * @return Data size in bytes. + */ +rpm_count_t rpmtdSize(rpmtd td); + /** \ingroup rpmtd * Retrieve tag of the container. * @param td Tag data container