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) qemuCaps, check_yajl) < 0)
goto cleanup; goto cleanup;
strflags = virBitmapString(qemuCaps->flags); strflags = virBitmapString(qemuCaps->flags, true);
VIR_DEBUG("Version %u.%u.%u, cooked version %u, flags %s", VIR_DEBUG("Version %u.%u.%u, cooked version %u, flags %s",
major, minor, micro, *version, NULLSTR(strflags)); major, minor, micro, *version, NULLSTR(strflags));
VIR_FREE(strflags); VIR_FREE(strflags);
@ -2377,7 +2377,7 @@ virQEMUCapsClear(virQEMUCapsPtr qemuCaps,
char *virQEMUCapsFlagsString(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: * virBitmapString:
* @bitmap: Pointer to bitmap * @bitmap: Pointer to bitmap
* @prefix: Whether to prepend "0x"
* *
* Convert @bitmap to printable string. * Convert @bitmap to printable string.
* *
* Returns pointer to the string or NULL on error. * Returns pointer to the string or NULL on error.
*/ */
char *virBitmapString(virBitmapPtr bitmap) char *
virBitmapString(virBitmapPtr bitmap,
bool prefix)
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
size_t sz; size_t sz;
virBufferAddLit(&buf, "0x"); if (prefix)
virBufferAddLit(&buf, "0x");
sz = bitmap->map_len; 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) int virBitmapGetBit(virBitmapPtr bitmap, size_t b, bool *result)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; 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; ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
char *virBitmapFormat(virBitmapPtr bitmap); char *virBitmapFormat(virBitmapPtr bitmap);