Lose the useless rpmtdToString()
authorPanu Matilainen <pmatilai@redhat.com>
Tue, 20 May 2008 09:07:38 +0000 (12:07 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 21 May 2008 09:04:51 +0000 (12:04 +0300)
- either use rpmtdFormat() or xstrdup() on rpmtdGetString() as appropriate

lib/formats.c
lib/psm.c
lib/rpmtd.c
lib/rpmtd.h
lib/rpmte.c

index 05dc5c8..ade9f8f 100644 (file)
@@ -621,7 +621,7 @@ static int instprefixTag(Header h, rpmtd td)
     } else if (headerGet(h, RPMTAG_INSTPREFIXES, &prefixes, flags)) {
        /* only return the first prefix of the array */
        td->type = RPM_STRING_TYPE;
-       td->data = rpmtdToString(&prefixes);
+       td->data = xstrdup(rpmtdGetString(&prefixes));
        td->freeData = 1;
        rpmtdFreeData(&prefixes);
        return 0;
index 21078b9..be37293 100644 (file)
--- a/lib/psm.c
+++ b/lib/psm.c
@@ -128,7 +128,7 @@ static int rpmInstallLoadMacros(rpmfi fi, Header h)
        switch (rpmtdType(&td)) {
        case RPM_INT32_TYPE: /* fallthrough */
        case RPM_STRING_TYPE:
-           body = rpmtdToString(&td);
+           body = rpmtdFormat(&td, RPMTD_FORMAT_STRING, NULL);
            addMacro(NULL, tagm->macroname, NULL, body, -1);
            free(body);
            break;
index 57fdd52..6f411a4 100644 (file)
@@ -165,43 +165,6 @@ char *rpmtdFormat(rpmtd td, rpmtdFormats fmt, const char *errmsg)
     return str;
 }
 
-char *rpmtdToString(rpmtd td)
-{
-    char *res = NULL;
-
-    switch (td->type) {
-       case RPM_STRING_TYPE:
-       case RPM_I18NSTRING_TYPE:
-       case RPM_STRING_ARRAY_TYPE: {
-           const char *s = rpmtdGetString(td);
-           if (s) {
-               res = xstrdup(s);
-           }
-           break;
-       }
-       case RPM_INT16_TYPE: {
-           uint16_t *num = rpmtdGetUint16(td);
-           if (num) {
-               rasprintf(&res, "%hd", *num);
-           }
-           break;
-       }
-       case RPM_INT32_TYPE: {
-           uint32_t *num = rpmtdGetUint32(td);
-           if (num) {
-               rasprintf(&res, "%d", *num);
-           }
-           break;
-       }
-       case RPM_BIN_TYPE: {
-           /* XXX TODO: convert to hex presentation */
-       }
-       default:
-           break;
-    }
-    return res;
-}
-
 int rpmtdFromArgv(rpmtd td, rpmTag tag, ARGV_t argv)
 {
     int count = argvCount(argv);
index 0c3388f..0edde14 100644 (file)
@@ -150,17 +150,6 @@ typedef enum rpmtdFormats_e {
 char *rpmtdFormat(rpmtd td, rpmtdFormats fmt, const char *errmsg);
 
 /** \ingroup rpmtd
- * Return data from tag container in string presentation.
- * Return malloced string presentation of current data in container,
- * converting from integers etc as necessary. On array types, data from
- * current iteration index is returned.
- * @param td           Tag data container
- * @return             String representation of current data (malloc'ed), 
- *                     NULL on error
- */
-char *rpmtdToString(rpmtd td);
-
-/** \ingroup rpmtd
  * Construct tag container from ARGV_t array.
  * Tag type is checked to be of string array type and array is checked
  * to be non-empty.
index 79d9316..3633c74 100644 (file)
@@ -91,13 +91,13 @@ static void addTE(rpmts ts, rpmte p, Header h,
     p->release = xstrdup(release);
 
     headerGet(h, RPMTAG_EPOCH, &td, HEADERGET_MINMEM);
-    p->epoch = rpmtdToString(&td);
+    p->epoch = rpmtdFormat(&td, RPMTD_FORMAT_STRING, NULL);
 
     p->arch = arch ? xstrdup(arch) : NULL;
     p->archScore = arch ? rpmMachineScore(RPM_MACHTABLE_INSTARCH, arch) : 0;
 
     headerGet(h, RPMTAG_OS, &td, HEADERGET_MINMEM);
-    p->os = rpmtdToString(&td);
+    p->os = xstrdup(rpmtdGetString(&td));
     p->osScore = p->os ? rpmMachineScore(RPM_MACHTABLE_INSTOS, p->os) : 0;
 
     p->isSource = headerIsSource(h);