[libvirt] [PATCHv2 03/15] util: new function for scaling numbers
Peter Krempa
pkrempa at redhat.com
Tue Mar 6 13:28:51 UTC 2012
On 03/06/2012 01:34 AM, Eric Blake wrote:
> Scaling an integer based on a suffix is something we plan on reusing
> in several contexts: XML parsing, virsh CLI parsing, and possibly
> elsewhere. Make it easy to reuse, as well as adding in support for
> powers of 1000.
>
> * src/util/util.h (virScaleInteger): New function.
> * src/util/util.c (virScaleInteger): Implement it.
> * src/libvirt_private.syms (util.h): Export it.
> ---
>
> v2: new, but borrows ideas from memory v1 3/3
>
> src/libvirt_private.syms | 1 +
> src/util/util.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++
> src/util/util.h | 4 +++
> 3 files changed, 71 insertions(+), 0 deletions(-)
>
> diff --git a/src/util/util.c b/src/util/util.c
> index 7c58c7b..1b71680 100644
> --- a/src/util/util.c
> +++ b/src/util/util.c
> @@ -1632,6 +1632,72 @@ virHexToBin(unsigned char c)
> }
> }
>
> +/* Scale an integer VALUE by an optional SUFFIX in-place, defaulting
> + * to SCALE if no suffix is present. Ensure that the result does not
> + * exceed LIMIT. Return 0 on success, -1 with error message raised on
> + * failure. */
I'd write a little bit more on how the base selection works depending on
the argument. Something like:
For power-of-two scaling use the binary prefixes (i.e. KiB, MiB), for
power of ten scaling use the SI prefixes (i.e. KB, Mb, ...).
> +int
> +virScaleInteger(unsigned long long *value, const char *suffix,
> + unsigned long long scale, unsigned long long limit)
Looks good. ACK
Peter
More information about the libvir-list
mailing list