util: Make prefix optional in virBitampString

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Martin Kletzander 2017-08-21 08:37:30 +02:00
parent 87a8a30d61
commit d127aced0a
3 changed files with 9 additions and 5 deletions

View File

@ -1510,7 +1510,7 @@ int virQEMUCapsParseHelpStr(const char *qemu,
qemuCaps, check_yajl) < 0)
goto cleanup;
strflags = virBitmapString(qemuCaps->flags);
strflags = virBitmapString(qemuCaps->flags, true);
VIR_DEBUG("Version %u.%u.%u, cooked version %u, flags %s",
major, minor, micro, *version, NULLSTR(strflags));
VIR_FREE(strflags);
@ -2377,7 +2377,7 @@ virQEMUCapsClear(virQEMUCapsPtr qemuCaps,
char *virQEMUCapsFlagsString(virQEMUCapsPtr qemuCaps)
{
return virBitmapString(qemuCaps->flags);
return virBitmapString(qemuCaps->flags, true);
}

View File

@ -312,17 +312,21 @@ int virBitmapGetBit(virBitmapPtr bitmap, size_t b, bool *result)
/**
* virBitmapString:
* @bitmap: Pointer to bitmap
* @prefix: Whether to prepend "0x"
*
* Convert @bitmap to printable string.
*
* Returns pointer to the string or NULL on error.
*/
char *virBitmapString(virBitmapPtr bitmap)
char *
virBitmapString(virBitmapPtr bitmap,
bool prefix)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
size_t sz;
virBufferAddLit(&buf, "0x");
if (prefix)
virBufferAddLit(&buf, "0x");
sz = bitmap->map_len;

View File

@ -80,7 +80,7 @@ bool virBitmapIsBitSet(virBitmapPtr bitmap, size_t b)
int virBitmapGetBit(virBitmapPtr bitmap, size_t b, bool *result)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK;
char *virBitmapString(virBitmapPtr bitmap)
char *virBitmapString(virBitmapPtr bitmap, bool prefix)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
char *virBitmapFormat(virBitmapPtr bitmap);