mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2024-12-23 00:25:27 +00:00
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:
parent
a3358798d6
commit
858acd4142
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue