From d5381c16a794e03c0e4f202daa3c882dc1876f41 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Tue, 20 May 2008 08:53:05 +0300 Subject: [PATCH] Handle RPM_CHAR_TYPE too in stringFormat() - used by filestates and nothing else apparently, duh.. --- lib/formats.c | 11 +++++++++-- lib/rpmtd.c | 12 ++++++++++++ lib/rpmtd.h | 10 ++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/formats.c b/lib/formats.c index f841a10..0f44688 100644 --- a/lib/formats.c +++ b/lib/formats.c @@ -51,11 +51,18 @@ static char * stringFormat(rpmtd td, char *formatPrefix, size_t padding) size_t need; switch (rpmtdType(td)) { + case RPM_INT8_TYPE: + case RPM_CHAR_TYPE: + need = 10 + padding + 20; /* we can do better, just for now ... */ + val = xmalloc(need); + strcat(formatPrefix, "hhd"); + sprintf(val, formatPrefix, *rpmtdGetChar(td)); + break; case RPM_INT16_TYPE: need = 10 + padding + 20; /* we can do better, just for now ... */ val = xmalloc(need); - strcat(formatPrefix, "d"); - sprintf(val, formatPrefix, *rpmtdGetUint32(td)); + strcat(formatPrefix, "hd"); + sprintf(val, formatPrefix, *rpmtdGetUint16(td)); break; case RPM_INT32_TYPE: need = 10 + padding + 20; /* we can do better, just for now ... */ diff --git a/lib/rpmtd.c b/lib/rpmtd.c index e0a29de..ee55435 100644 --- a/lib/rpmtd.c +++ b/lib/rpmtd.c @@ -82,6 +82,18 @@ int rpmtdNext(rpmtd td) return i; } +char * rpmtdGetChar(rpmtd td) +{ + char *res = NULL; + + assert(td != NULL); + + if (td->type == RPM_CHAR_TYPE) { + int ix = (td->ix >= 0 ? td->ix : 0); + res = (char *) td->data + ix; + } + return res; +} uint16_t * rpmtdGetUint16(rpmtd td) { uint16_t *res = NULL; diff --git a/lib/rpmtd.h b/lib/rpmtd.h index b7f1a20..c058f5b 100644 --- a/lib/rpmtd.h +++ b/lib/rpmtd.h @@ -80,6 +80,16 @@ int rpmtdInit(rpmtd td); int rpmtdNext(rpmtd td); /** \ingroup rpmtd + * Return char data from tag container. + * For scalar return type, just return pointer to the integer. On array + * types, return pointer to current iteration index. If the tag container + * is not for char type, NULL is returned. + * @param td Tag data container + * @return Pointer to uint16_t, NULL on error + */ +char *rpmtdGetChar(rpmtd td); + +/** \ingroup rpmtd * Return uint16_t data from tag container. * For scalar return type, just return pointer to the integer. On array * types, return pointer to current iteration index. If the tag container -- 2.7.4