diff options
author | Markus Armbruster <armbru@redhat.com> | 2017-02-21 21:13:58 +0100 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2017-02-23 20:35:36 +0100 |
commit | d2734d2629266006b0413433778474d5801c60be (patch) | |
tree | d02a4013292c549a001879034250be87fcb9b644 /util | |
parent | 0b742797aaada3a2e243175a69d542d2ed997aac (diff) |
util/cutils: New qemu_strtosz_metric()
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.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <1487708048-2131-15-git-send-email-armbru@redhat.com>
Diffstat (limited to 'util')
-rw-r--r-- | util/cutils.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/util/cutils.c b/util/cutils.c index 6397424111..b46e254f83 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -205,8 +205,8 @@ static int64_t suffix_mul(char suffix, int64_t unit) * in *end, if not NULL. Return -ERANGE on overflow, Return -EINVAL on * other error. */ -int64_t qemu_strtosz_suffix_unit(const char *nptr, char **end, - const char default_suffix, int64_t unit) +static int64_t do_strtosz(const char *nptr, char **end, + const char default_suffix, int64_t unit) { int64_t retval = -EINVAL; char *endptr; @@ -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); } +int64_t qemu_strtosz_metric(const char *nptr, char **end) +{ + return do_strtosz(nptr, end, QEMU_STRTOSZ_DEFSUFFIX_B, 1000); +} + /** * Helper function for error checking after strtol() and the like */ |