mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-02-01 23:11:02 +00:00
util/cutils: Return qemu_strtosz*() error and value separately
This makes qemu_strtosz(), qemu_strtosz_mebi() and qemu_strtosz_metric() similar to qemu_strtoi64(), except negative values are rejected. Backports commit f17fd4fdf0df3d2f3444399d04c38d22b9a3e1b7 from qemu
This commit is contained in:
parent
6093e67947
commit
8650d0213c
|
@ -131,9 +131,9 @@ int qemu_strtoi64(const char *nptr, const char **endptr, int base,
|
|||
int qemu_strtou64(const char *nptr, const char **endptr, int base,
|
||||
uint64_t *result);
|
||||
|
||||
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);
|
||||
int qemu_strtosz(const char *nptr, char **end, int64_t *result);
|
||||
int qemu_strtosz_MiB(const char *nptr, char **end, int64_t *result);
|
||||
int qemu_strtosz_metric(const char *nptr, char **end, int64_t *result);
|
||||
|
||||
#define K_BYTE (1ULL << 10)
|
||||
#define M_BYTE (1ULL << 20)
|
||||
|
|
|
@ -2181,10 +2181,11 @@ static void x86_cpu_parse_featurestr(CPUState *cs, char *features,
|
|||
|
||||
/* Special case: */
|
||||
if (!strcmp(name, "tsc-freq")) {
|
||||
int ret;
|
||||
int64_t tsc_freq;
|
||||
|
||||
tsc_freq = qemu_strtosz_metric(val, NULL);
|
||||
if (tsc_freq < 0) {
|
||||
ret = qemu_strtosz_metric(val, NULL, &tsc_freq);
|
||||
if (ret < 0) {
|
||||
error_setg(errp, "bad numerical value %s", val);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -154,10 +154,11 @@ static int64_t suffix_mul(char suffix, int64_t unit)
|
|||
* in *end, if not NULL. Return -ERANGE on overflow, Return -EINVAL on
|
||||
* other error.
|
||||
*/
|
||||
static int64_t do_strtosz(const char *nptr, char **end,
|
||||
const char default_suffix, int64_t unit)
|
||||
static int do_strtosz(const char *nptr, char **end,
|
||||
const char default_suffix, int64_t unit,
|
||||
int64_t *result)
|
||||
{
|
||||
int64_t retval;
|
||||
int retval;
|
||||
char *endptr;
|
||||
unsigned char c;
|
||||
int mul_required = 0;
|
||||
|
@ -189,7 +190,8 @@ static int64_t do_strtosz(const char *nptr, char **end,
|
|||
retval = -ERANGE;
|
||||
goto out;
|
||||
}
|
||||
retval = (int64_t)(val * mul);
|
||||
*result = (int64_t)(val * mul);
|
||||
retval = 0;
|
||||
|
||||
out:
|
||||
if (end) {
|
||||
|
@ -201,19 +203,19 @@ out:
|
|||
return retval;
|
||||
}
|
||||
|
||||
int64_t qemu_strtosz(const char *nptr, char **end)
|
||||
int qemu_strtosz(const char *nptr, char **end, int64_t *result)
|
||||
{
|
||||
return do_strtosz(nptr, end, 'B', 1024);
|
||||
return do_strtosz(nptr, end, 'B', 1024, result);
|
||||
}
|
||||
|
||||
int64_t qemu_strtosz_MiB(const char *nptr, char **end)
|
||||
int qemu_strtosz_MiB(const char *nptr, char **end, int64_t *result)
|
||||
{
|
||||
return do_strtosz(nptr, end, 'M', 1024);
|
||||
return do_strtosz(nptr, end, 'M', 1024, result);
|
||||
}
|
||||
|
||||
int64_t qemu_strtosz_metric(const char *nptr, char **end)
|
||||
int qemu_strtosz_metric(const char *nptr, char **end, int64_t *result)
|
||||
{
|
||||
return do_strtosz(nptr, end, 'B', 1000);
|
||||
return do_strtosz(nptr, end, 'B', 1000, result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue