int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
{
int64_t retval = -1;
- char *endptr, c, d;
+ char *endptr;
+ unsigned char c, d;
int mul_required = 0;
double val, mul, integral, fraction;
if (isnan(val) || endptr == nptr || errno != 0) {
goto fail;
}
- integral = modf(val, &fraction);
- if (integral != 0) {
+ fraction = modf(val, &integral);
+ if (fraction != 0) {
mul_required = 1;
}
/*
*/
c = *endptr;
d = c;
- if (isspace(c) || c == '\0' || c == ',') {
+ if (qemu_isspace(c) || c == '\0' || c == ',') {
c = 0;
if (default_suffix) {
d = default_suffix;
d = c;
}
}
- switch (d) {
- case 'B':
- case 'b':
+ switch (qemu_toupper(d)) {
+ case STRTOSZ_DEFSUFFIX_B:
mul = 1;
if (mul_required) {
goto fail;
}
break;
- case 'K':
- case 'k':
+ case STRTOSZ_DEFSUFFIX_KB:
mul = 1 << 10;
break;
case 0:
if (mul_required) {
goto fail;
}
- case 'M':
- case 'm':
+ case STRTOSZ_DEFSUFFIX_MB:
mul = 1ULL << 20;
break;
- case 'G':
- case 'g':
+ case STRTOSZ_DEFSUFFIX_GB:
mul = 1ULL << 30;
break;
- case 'T':
- case 't':
+ case STRTOSZ_DEFSUFFIX_TB:
mul = 1ULL << 40;
break;
default:
*/
if (c != 0) {
endptr++;
- if (!isspace(*endptr) && *endptr != ',' && *endptr != 0) {
+ if (!qemu_isspace(*endptr) && *endptr != ',' && *endptr != 0) {
goto fail;
}
}