Add rpmtdGetNumber() for getting numeric values from tag container
- returns the value (as opposed to pointer to, like the rpmtdGetUint32() and the like do) of any numeric type as uint64_t (largest supported integer type so everything can be converted to it) - handy when you don't really care what the internal presentation is - there's no rpmtdGetNextNumber() as there's no meaningful way to return end-of-iteration here
This commit is contained in:
parent
ed5306b0be
commit
2db2c376b3
26
lib/rpmtd.c
26
lib/rpmtd.c
|
@ -217,6 +217,32 @@ const char * rpmtdGetString(rpmtd td)
|
|||
return str;
|
||||
}
|
||||
|
||||
uint64_t rpmtdGetNumber(rpmtd td)
|
||||
{
|
||||
assert(td != NULL);
|
||||
uint64_t val = 0;
|
||||
int ix = (td->ix >= 0 ? td->ix : 0);
|
||||
|
||||
switch (td->type) {
|
||||
case RPM_INT64_TYPE:
|
||||
val = *((uint64_t *) td->data + ix);
|
||||
break;
|
||||
case RPM_INT32_TYPE:
|
||||
val = *((uint32_t *) td->data + ix);
|
||||
break;
|
||||
case RPM_INT16_TYPE:
|
||||
val = *((uint16_t *) td->data + ix);
|
||||
break;
|
||||
case RPM_INT8_TYPE:
|
||||
case RPM_CHAR_TYPE:
|
||||
val = *((uint8_t *) td->data + ix);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
char *rpmtdFormat(rpmtd td, rpmtdFormats fmt, const char *errmsg)
|
||||
{
|
||||
headerTagFormatFunction func = rpmHeaderFormatFuncByValue(fmt);
|
||||
|
|
11
lib/rpmtd.h
11
lib/rpmtd.h
|
@ -185,6 +185,17 @@ uint64_t * rpmtdGetUint64(rpmtd td);
|
|||
*/
|
||||
const char * rpmtdGetString(rpmtd td);
|
||||
|
||||
/** \ingroup rpmtd
|
||||
* Return numeric value from tag container.
|
||||
* Returns the value of numeric container (RPM_NUMERIC_CLASS) from
|
||||
* current iteration index as uint64_t regardless of its internal
|
||||
* presentation (8/16/32/64-bit integer).
|
||||
* @param td Tag data container
|
||||
* @return Value of current iteration item as uint64_t,
|
||||
* 0 for non-numeric types (error)
|
||||
*/
|
||||
uint64_t rpmtdGetNumber(rpmtd td);
|
||||
|
||||
typedef enum rpmtdFormats_e {
|
||||
RPMTD_FORMAT_STRING = 0, /* plain string (any type) */
|
||||
RPMTD_FORMAT_ARMOR = 1, /* ascii armor format (bin types) */
|
||||
|
|
Loading…
Reference in New Issue