summaryrefslogtreecommitdiff
path: root/lib/formats.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2008-11-17 12:23:19 +0200
committerPanu Matilainen <pmatilai@redhat.com>2008-11-17 12:23:19 +0200
commitee6c147a239feb6a5587758b19192f274bd0a529 (patch)
treec1d27b65f0ea61ecfd9627c3114f99988a6aa80f /lib/formats.c
parentd97e357560ad9111b95da9bf2126a7bde3b4bac1 (diff)
downloadrpm-ee6c147a239feb6a5587758b19192f274bd0a529.tar.gz
rpm-ee6c147a239feb6a5587758b19192f274bd0a529.tar.bz2
rpm-ee6c147a239feb6a5587758b19192f274bd0a529.zip
Take advantage of rpmtdGetNumber() for numeric format specifiers
- octalFormat() and hexFormat() now work for any number, not just int32, fixing rhbz#471820 - use a common helper-function for both formats, they only differ by o/x
Diffstat (limited to 'lib/formats.c')
-rw-r--r--lib/formats.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/lib/formats.c b/lib/formats.c
index 4aab74808..fcebef91c 100644
--- a/lib/formats.c
+++ b/lib/formats.c
@@ -67,25 +67,29 @@ static char * stringFormat(rpmtd td, char *formatPrefix)
return val;
}
-/**
- * octalFormat.
- * @param td tag data container
- * @param formatPrefix sprintf format string
- * @return formatted string
- */
-static char * octalFormat(rpmtd td, char * formatPrefix)
+static char * numFormat(rpmtd td, char * formatPrefix, char *format)
{
char * val = NULL;
- if (rpmtdType(td) != RPM_INT32_TYPE) {
+ if (rpmtdClass(td) != RPM_NUMERIC_CLASS) {
val = xstrdup(_("(not a number)"));
} else {
- strcat(formatPrefix, "o");
- rasprintf(&val, formatPrefix, *rpmtdGetUint32(td));
+ strcat(formatPrefix, format);
+ rasprintf(&val, formatPrefix, rpmtdGetNumber(td));
}
return val;
}
+/**
+ * octalFormat.
+ * @param td tag data container
+ * @param formatPrefix sprintf format string
+ * @return formatted string
+ */
+static char * octalFormat(rpmtd td, char * formatPrefix)
+{
+ return numFormat(td, formatPrefix, "o");
+}
/**
* hexFormat.
@@ -95,16 +99,7 @@ static char * octalFormat(rpmtd td, char * formatPrefix)
*/
static char * hexFormat(rpmtd td, char * formatPrefix)
{
- char * val = NULL;
-
- if (rpmtdType(td) != RPM_INT32_TYPE) {
- val = xstrdup(_("(not a number)"));
- } else {
- strcat(formatPrefix, "x");
- rasprintf(&val, formatPrefix, *rpmtdGetUint32(td));
- }
-
- return val;
+ return numFormat(td, formatPrefix, "x");
}
/**