Add two new convenience functions for header string data
authorPanu Matilainen <pmatilai@redhat.com>
Tue, 1 Sep 2009 14:10:18 +0000 (17:10 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 2 Sep 2009 07:48:54 +0000 (10:48 +0300)
- headerGetString() for retrieving const strings directly from header memory
- headerGetAsString() for converting any non-array tag to string

lib/header.c
lib/header.h

index f9d553d..85cf2fd 100644 (file)
@@ -1905,3 +1905,28 @@ void headerSetInstance(Header h, unsigned int instance)
 {
     h->instance = instance;
 }    
+
+char * headerGetAsString(Header h, rpmTag tag)
+{
+    char *res = NULL;
+    struct rpmtd_s td;
+
+    if (headerGet(h, tag, &td, HEADERGET_EXT) && rpmtdCount(&td) == 1) {
+       res = rpmtdFormat(&td, RPMTD_FORMAT_STRING, NULL);
+       rpmtdFreeData(&td);
+    }
+    return res;
+}
+
+const char * headerGetString(Header h, rpmTag tag)
+{
+    const char *res = NULL;
+    struct rpmtd_s td;
+
+    if (headerGet(h, tag, &td, HEADERGET_MINMEM) && rpmtdCount(&td) == 1) {
+       res = rpmtdGetString(&td);
+       rpmtdFreeData(&td);
+    }
+    return res;
+}
+
index 801ecdf..d4f88fe 100644 (file)
@@ -371,6 +371,22 @@ char * headerGetNEVRA(Header h, const char ** np );
 char * headerGetEVR(Header h, const char **np);
 
 /** \ingroup header
+ * Return any non-array tag from header, converted to string
+ * @param h            header
+ * @param tag          tag to retrieve
+ * @return             string pointer (malloced) or NULL on failure
+ */
+char * headerGetAsString(Header h, rpmTag tag);
+
+/** \ingroup header
+ * Return a simple string tag from header
+ * @param h            header
+ * @param tag          tag to retrieve
+ * @return             string pointer (to header memory) or NULL on failure
+ */
+const char * headerGetString(Header h, rpmTag tag);
+
+/** \ingroup header
  * Return header color.
  * @param h            header
  * @return             header color