From: Panu Matilainen Date: Thu, 12 Jun 2008 12:01:58 +0000 (+0300) Subject: Move 32 to 64 bit tag conversion to helper function X-Git-Tag: tznext/4.11.0.1.tizen20130304~3903 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3c5a8a7046cb6437f7a94742f5531a64165db684;p=tools%2Flibrpm-tizen.git Move 32 to 64 bit tag conversion to helper function --- diff --git a/lib/tagexts.c b/lib/tagexts.c index 966beeb..b1324c0 100644 --- a/lib/tagexts.c +++ b/lib/tagexts.c @@ -564,43 +564,52 @@ static int groupTag(Header h, rpmtd td) return i18nTag(h, RPMTAG_GROUP, td); } -/** - * Retrieve file sizes as 64bit regardless of how they're stored. - * @param h header - * @retval td tag data container - * @return 1 on success +/* + * Helper to convert 32bit tag to 64bit version. + * If header has new 64bit tag then just return the data, + * otherwise convert 32bit old tag data to 64bit values. + * For consistency, always return malloced data. */ -static int longfilesizesTag(Header h, rpmtd td) +static int get64(Header h, rpmtd td, rpmTag newtag, rpmTag oldtag) { int rc; - /* - * If header has LONGFILESIZES then we've nothing special to do, - * otherwise convert 32bit FILESIZES to 64bit values. - * For consistency, always return malloced data. - */ - if (headerIsEntry(h, RPMTAG_LONGFILESIZES)) { - rc = headerGet(h, RPMTAG_LONGFILESIZES, td, HEADERGET_ALLOC); + if (headerIsEntry(h, newtag)) { + rc = headerGet(h, newtag, td, HEADERGET_ALLOC); } else { - struct rpmtd_s filesizes; - rpm_off_t *oldsize; - rpm_loff_t *longsize; - - rc = headerGet(h, RPMTAG_FILESIZES, &filesizes, HEADERGET_MINMEM); - td->type = RPM_INT64_TYPE; - td->count = filesizes.count; - td->flags = RPMTD_ALLOCED; - td->data = xmalloc(sizeof(*longsize) * rpmtdCount(&filesizes)); - longsize = td->data; - while ((oldsize = rpmtdNextUint32(&filesizes))) { - *longsize++ = *oldsize; - } - rpmtdFreeData(&filesizes); + struct rpmtd_s olddata; + uint32_t *d32 = NULL; + uint64_t *d64 = NULL; + + headerGet(h, oldtag, &olddata, HEADERGET_MINMEM); + if (rpmtdType(&olddata) == RPM_INT32_TYPE) { + td->type = RPM_INT64_TYPE; + td->count = olddata.count; + td->flags = RPMTD_ALLOCED; + td->data = xmalloc(sizeof(*d64) * td->count); + d64 = td->data; + while ((d32 = rpmtdNextUint32(&olddata))) { + *d64++ = *d32; + } + } + rpmtdFreeData(&olddata); + rc = d64 ? 1 : 0; } return rc; } +/** + * Retrieve file sizes as 64bit regardless of how they're stored. + * @param h header + * @retval td tag data container + * @return 1 on success + */ +static int longfilesizesTag(Header h, rpmtd td) +{ + return get64(h, td, RPMTAG_LONGFILESIZES, RPMTAG_FILESIZES); +} + void *rpmHeaderTagFunc(rpmTag tag) { const struct headerTagFunc_s * ext;