From 4c63745fe818b616feb3395c953ac1833d65b551 Mon Sep 17 00:00:00 2001 From: jbj Date: Thu, 17 Mar 2005 17:12:26 +0000 Subject: [PATCH] Add tagType(). CVS patchset: 7818 CVS date: 2005/03/17 17:12:26 --- lib/rpmlib.h | 16 ++++++++++++---- rpmdb/tagname.c | 23 ++++++++++++++++++++++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/rpmlib.h b/lib/rpmlib.h index 0a24470..006721d 100644 --- a/lib/rpmlib.h +++ b/lib/rpmlib.h @@ -1058,9 +1058,17 @@ void rpmShowRpmlibProvides(FILE * fp) /*@}*/ /** - * Return name of tag from value. + * Return tag data type from value. * @param tag tag value - * @return name of tag + * @return tag data type, RPM_NULL_TYPE on not found. + */ +int tagType(int tag) + /*@*/; + +/** + * Return tag name from value. + * @param tag tag value + * @return tag name, "(unknown)" on not found */ /*@-redecl@*/ /*@observer@*/ extern const char *const tagName(int tag) @@ -1068,9 +1076,9 @@ void rpmShowRpmlibProvides(FILE * fp) /*@=redecl@*/ /** - * Return value of tag from name. + * Return tag value from name. * @param tagstr name of tag - * @return tag value + * @return tag value, -1 on not found */ int tagValue(const char * tagstr) /*@*/; diff --git a/rpmdb/tagname.c b/rpmdb/tagname.c index 02e4a8c..ef646ed 100644 --- a/rpmdb/tagname.c +++ b/rpmdb/tagname.c @@ -7,11 +7,32 @@ #include #include "debug.h" +static int tagcmp(const void * a, const void * b) + /*@*/ +{ + const headerTagTableEntry aptr = a; + const headerTagTableEntry bptr = b; + return (aptr->val - bptr->val); +} + +int tagType(int tag) +{ + headerTagTableEntry t = memset(alloca(sizeof(*t)), 0, sizeof(*t)); + headerTagTableEntry needle; + int tagtype = RPM_NULL_TYPE; + + t->val = tag; + needle = bsearch(t, rpmTagTable, rpmTagTableSize, sizeof(*t), tagcmp); + if (needle != NULL) + tagtype = needle->type; + return tagtype; +} + const char *const tagName(int tag) { - int i; static char nameBuf[128]; /* XXX yuk */ char *s; + int i; switch (tag) { case RPMDBI_PACKAGES: -- 2.7.4