提交 8dddfb55 编写于 作者: M Markus Armbruster 提交者: Anthony Liguori

cutils: Drop broken support for zero strtosz default_suffix

Commit 9f9b17a4's strtosz() defaults a missing suffix to 'M', except
it rejects fractions then (switch case 0).

When commit d8427002 introduced strtosz_suffix(), that changed:
fractions are no longer rejected, because we go to switch case 'M' on
missing suffix now.  Not mentioned in commit message, probably
unintentional.  Not worth changing back now.

Because case 0 is still around, you can get the old behavior by
passing a zero default_suffix to strtosz_suffix() or
strtosz_suffix_unit().  Undocumented and not used.  Drop.

Commit d8427002 also neglected to update the function comment.  Fix it
up.
Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 21d4a791
...@@ -317,10 +317,9 @@ int fcntl_setfl(int fd, int flag) ...@@ -317,10 +317,9 @@ int fcntl_setfl(int fd, int flag)
/* /*
* Convert string to bytes, allowing either B/b for bytes, K/k for KB, * Convert string to bytes, allowing either B/b for bytes, K/k for KB,
* M/m for MB, G/g for GB or T/t for TB. Default without any postfix * M/m for MB, G/g for GB or T/t for TB. End pointer will be returned
* is MB. End pointer will be returned in *end, if not NULL. A valid * in *end, if not NULL. A valid value must be terminated by
* value must be terminated by whitespace, ',' or '\0'. Return -1 on * whitespace, ',' or '\0'. Return -1 on error.
* error.
*/ */
int64_t strtosz_suffix_unit(const char *nptr, char **end, int64_t strtosz_suffix_unit(const char *nptr, char **end,
const char default_suffix, int64_t unit) const char default_suffix, int64_t unit)
...@@ -349,11 +348,7 @@ int64_t strtosz_suffix_unit(const char *nptr, char **end, ...@@ -349,11 +348,7 @@ int64_t strtosz_suffix_unit(const char *nptr, char **end,
d = c; d = c;
if (qemu_isspace(c) || c == '\0' || c == ',') { if (qemu_isspace(c) || c == '\0' || c == ',') {
c = 0; c = 0;
if (default_suffix) { d = default_suffix;
d = default_suffix;
} else {
d = c;
}
} }
switch (qemu_toupper(d)) { switch (qemu_toupper(d)) {
case STRTOSZ_DEFSUFFIX_B: case STRTOSZ_DEFSUFFIX_B:
...@@ -365,10 +360,6 @@ int64_t strtosz_suffix_unit(const char *nptr, char **end, ...@@ -365,10 +360,6 @@ int64_t strtosz_suffix_unit(const char *nptr, char **end,
case STRTOSZ_DEFSUFFIX_KB: case STRTOSZ_DEFSUFFIX_KB:
mul = unit; mul = unit;
break; break;
case 0:
if (mul_required) {
goto fail;
}
case STRTOSZ_DEFSUFFIX_MB: case STRTOSZ_DEFSUFFIX_MB:
mul = unit * unit; mul = unit * unit;
break; break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册