mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-01 17:35:17 +00:00
Introduce virBitmapDataToString
For converting bitmap data to human-readable strings.
This commit is contained in:
parent
d4edce5f1e
commit
7d8afc4725
@ -970,6 +970,7 @@ virBitmapClearAll;
|
|||||||
virBitmapClearBit;
|
virBitmapClearBit;
|
||||||
virBitmapCopy;
|
virBitmapCopy;
|
||||||
virBitmapCountBits;
|
virBitmapCountBits;
|
||||||
|
virBitmapDataToString;
|
||||||
virBitmapEqual;
|
virBitmapEqual;
|
||||||
virBitmapFormat;
|
virBitmapFormat;
|
||||||
virBitmapFree;
|
virBitmapFree;
|
||||||
|
@ -707,3 +707,28 @@ virBitmapCountBits(virBitmapPtr bitmap)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virBitmapDataToString:
|
||||||
|
* @data: the data
|
||||||
|
* @len: length of @data in bytes
|
||||||
|
*
|
||||||
|
* Convert a chunk of data containing bits information to a human
|
||||||
|
* readable string, e.g.: 0-1,4
|
||||||
|
*
|
||||||
|
* Returns: a string representation of the data, or NULL on error
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
virBitmapDataToString(void *data,
|
||||||
|
int len)
|
||||||
|
{
|
||||||
|
virBitmapPtr map = NULL;
|
||||||
|
char *ret = NULL;
|
||||||
|
|
||||||
|
if (!(map = virBitmapNewData(data, len)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
ret = virBitmapFormat(map);
|
||||||
|
virBitmapFree(map);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -111,4 +111,8 @@ ssize_t virBitmapNextClearBit(virBitmapPtr bitmap, ssize_t pos)
|
|||||||
size_t virBitmapCountBits(virBitmapPtr bitmap)
|
size_t virBitmapCountBits(virBitmapPtr bitmap)
|
||||||
ATTRIBUTE_NONNULL(1);
|
ATTRIBUTE_NONNULL(1);
|
||||||
|
|
||||||
|
char *virBitmapDataToString(void *data,
|
||||||
|
int len)
|
||||||
|
ATTRIBUTE_NONNULL(1);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -255,5 +255,4 @@ char *virStringReplace(const char *haystack,
|
|||||||
const char *newneedle)
|
const char *newneedle)
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
|
||||||
|
|
||||||
|
|
||||||
#endif /* __VIR_STRING_H__ */
|
#endif /* __VIR_STRING_H__ */
|
||||||
|
@ -266,7 +266,7 @@ test4(const void *data ATTRIBUTE_UNUSED)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* test for virBitmapNewData/ToData */
|
/* test for virBitmapNewData/ToData/DataToString */
|
||||||
static int
|
static int
|
||||||
test5(const void *v ATTRIBUTE_UNUSED)
|
test5(const void *v ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
@ -278,6 +278,7 @@ test5(const void *v ATTRIBUTE_UNUSED)
|
|||||||
size_t i;
|
size_t i;
|
||||||
ssize_t j;
|
ssize_t j;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
char *str = NULL;
|
||||||
|
|
||||||
bitmap = virBitmapNewData(data, sizeof(data));
|
bitmap = virBitmapNewData(data, sizeof(data));
|
||||||
if (!bitmap)
|
if (!bitmap)
|
||||||
@ -307,8 +308,19 @@ test5(const void *v ATTRIBUTE_UNUSED)
|
|||||||
data2[4] != 0x04)
|
data2[4] != 0x04)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
if (!(str = virBitmapDataToString(data, sizeof(data))))
|
||||||
|
goto error;
|
||||||
|
if (STRNEQ(str, "0,9,34"))
|
||||||
|
goto error;
|
||||||
|
VIR_FREE(str);
|
||||||
|
if (!(str = virBitmapDataToString(data2, sizeof(data2))))
|
||||||
|
goto error;
|
||||||
|
if (STRNEQ(str, "0,2,9,15,34"))
|
||||||
|
goto error;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
error:
|
error:
|
||||||
|
VIR_FREE(str);
|
||||||
virBitmapFree(bitmap);
|
virBitmapFree(bitmap);
|
||||||
VIR_FREE(data2);
|
VIR_FREE(data2);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user