util/cutils: New qemu_strtosz()

Most callers of qemu_strtosz_suffix() pass QEMU_STRTOSZ_DEFSUFFIX_B.
Capture the pattern in new qemu_strtosz().

Inline qemu_strtosz_suffix() into its only remaining caller.

Backports commit 466dea14e677555dd24465aca75d00a3537ad062 from qemu
This commit is contained in:
Markus Armbruster 2018-03-02 08:50:54 -05:00 committed by Lioncash
parent a3358798d6
commit 858acd4142
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
2 changed files with 13 additions and 20 deletions

View file

@ -130,22 +130,8 @@ int qemu_strtoi64(const char *nptr, const char **endptr, int base,
int64_t *result);
int qemu_strtou64(const char *nptr, const char **endptr, int base,
uint64_t *result);
/*
* qemu_strtosz() suffixes used to specify the default treatment of an
* argument passed to qemu_strtosz() without an explicit suffix.
* These should be defined using upper case characters in the range
* A-Z, as qemu_strtosz() will use qemu_toupper() on the given argument
* prior to comparison.
*/
#define QEMU_STRTOSZ_DEFSUFFIX_EB 'E'
#define QEMU_STRTOSZ_DEFSUFFIX_PB 'P'
#define QEMU_STRTOSZ_DEFSUFFIX_TB 'T'
#define QEMU_STRTOSZ_DEFSUFFIX_GB 'G'
#define QEMU_STRTOSZ_DEFSUFFIX_MB 'M'
#define QEMU_STRTOSZ_DEFSUFFIX_KB 'K'
#define QEMU_STRTOSZ_DEFSUFFIX_B 'B'
int64_t qemu_strtosz_suffix(const char *nptr, char **end,
const char default_suffix);
int64_t qemu_strtosz(const char *nptr, char **end);
int64_t qemu_strtosz_MiB(const char *nptr, char **end);
int64_t qemu_strtosz_metric(const char *nptr, char **end);

View file

@ -127,6 +127,14 @@ char *qemu_strsep(char **input, const char *delim)
return result;
}
#define QEMU_STRTOSZ_DEFSUFFIX_EB 'E'
#define QEMU_STRTOSZ_DEFSUFFIX_PB 'P'
#define QEMU_STRTOSZ_DEFSUFFIX_TB 'T'
#define QEMU_STRTOSZ_DEFSUFFIX_GB 'G'
#define QEMU_STRTOSZ_DEFSUFFIX_MB 'M'
#define QEMU_STRTOSZ_DEFSUFFIX_KB 'K'
#define QEMU_STRTOSZ_DEFSUFFIX_B 'B'
static int64_t suffix_mul(char suffix, int64_t unit)
{
switch (qemu_toupper(suffix)) {
@ -197,15 +205,14 @@ fail:
return retval;
}
int64_t qemu_strtosz_suffix(const char *nptr, char **end,
const char default_suffix)
int64_t qemu_strtosz(const char *nptr, char **end)
{
return do_strtosz(nptr, end, default_suffix, 1024);
return do_strtosz(nptr, end, QEMU_STRTOSZ_DEFSUFFIX_B, 1024);
}
int64_t qemu_strtosz_MiB(const char *nptr, char **end)
{
return qemu_strtosz_suffix(nptr, end, QEMU_STRTOSZ_DEFSUFFIX_MB);
return do_strtosz(nptr, end, QEMU_STRTOSZ_DEFSUFFIX_MB, 1024);
}
int64_t qemu_strtosz_metric(const char *nptr, char **end)