qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 14/24] util/cutils: New qemu_strtosz_metric()


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH 14/24] util/cutils: New qemu_strtosz_metric()
Date: Fri, 17 Feb 2017 14:44:07 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0

On 02/14/2017 04:26 AM, Markus Armbruster wrote:
> To parse numbers with metric suffixes, we use
> 
>     qemu_strtosz_suffix_unit(nptr, &eptr, QEMU_STRTOSZ_DEFSUFFIX_B, 1000)
> 
> Capture this in a new function for legibility:
> 
>     qemu_strtosz_metric(nptr, &eptr)
> 
> Replace test_qemu_strtosz_suffix_unit() by test_qemu_strtosz_metric().
> 
> Rename qemu_strtosz_suffix_unit() to do_strtosz() and give it internal
> linkage.

I don't know if you do this later, but coreutils (via gnulib) has a nice
convention that:

1k   => 1024
1kB  => 1000
1kiB => 1024

where the suffix can be used to express metric or power-of-two, letting
the user choose which scale they want rather than hard-coding the scale.
 But implementing that is beyond this scope of this particular patch.

> 
> Signed-off-by: Markus Armbruster <address@hidden>
> ---

> @@ -251,7 +251,7 @@ fail:
>  int64_t qemu_strtosz_suffix(const char *nptr, char **end,
>                              const char default_suffix)
>  {
> -    return qemu_strtosz_suffix_unit(nptr, end, default_suffix, 1024);
> +    return do_strtosz(nptr, end, default_suffix, 1024);
>  }
>  
>  int64_t qemu_strtosz(const char *nptr, char **end)
> @@ -259,6 +259,11 @@ int64_t qemu_strtosz(const char *nptr, char **end)
>      return qemu_strtosz_suffix(nptr, end, QEMU_STRTOSZ_DEFSUFFIX_MB);

Do you also want to convert this one to do_strtosz() to avoid
double-forwarding?

Either way,

Reviewed-by: Eric Blake <address@hidden>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]