提交 a732e1ba 编写于 作者: J Joerg Roedel 提交者: Marcelo Tosatti

qemu: Add strtosz_suffix_unit function

This function does the same as the strtosz_suffix function
except that it allows to specify the unit to which the
k/M/B/T suffixes apply. This function will be used later to
parse the tsc-frequency from the command-line.
Signed-off-by: NJoerg Roedel <joerg.roedel@amd.com>
Signed-off-by: NMarcelo Tosatti <mtosatti@redhat.com>
上级 2a1ac12b
...@@ -322,7 +322,8 @@ int fcntl_setfl(int fd, int flag) ...@@ -322,7 +322,8 @@ int fcntl_setfl(int fd, int flag)
* value must be terminated by whitespace, ',' or '\0'. Return -1 on * value must be terminated by whitespace, ',' or '\0'. Return -1 on
* error. * error.
*/ */
int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) int64_t strtosz_suffix_unit(const char *nptr, char **end,
const char default_suffix, int64_t unit)
{ {
int64_t retval = -1; int64_t retval = -1;
char *endptr; char *endptr;
...@@ -362,20 +363,20 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) ...@@ -362,20 +363,20 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
} }
break; break;
case STRTOSZ_DEFSUFFIX_KB: case STRTOSZ_DEFSUFFIX_KB:
mul = 1 << 10; mul = unit;
break; break;
case 0: case 0:
if (mul_required) { if (mul_required) {
goto fail; goto fail;
} }
case STRTOSZ_DEFSUFFIX_MB: case STRTOSZ_DEFSUFFIX_MB:
mul = 1ULL << 20; mul = unit * unit;
break; break;
case STRTOSZ_DEFSUFFIX_GB: case STRTOSZ_DEFSUFFIX_GB:
mul = 1ULL << 30; mul = unit * unit * unit;
break; break;
case STRTOSZ_DEFSUFFIX_TB: case STRTOSZ_DEFSUFFIX_TB:
mul = 1ULL << 40; mul = unit * unit * unit * unit;
break; break;
default: default:
goto fail; goto fail;
...@@ -405,6 +406,11 @@ fail: ...@@ -405,6 +406,11 @@ fail:
return retval; return retval;
} }
int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
{
return strtosz_suffix_unit(nptr, end, default_suffix, 1024);
}
int64_t strtosz(const char *nptr, char **end) int64_t strtosz(const char *nptr, char **end)
{ {
return strtosz_suffix(nptr, end, STRTOSZ_DEFSUFFIX_MB); return strtosz_suffix(nptr, end, STRTOSZ_DEFSUFFIX_MB);
......
...@@ -157,6 +157,8 @@ int fcntl_setfl(int fd, int flag); ...@@ -157,6 +157,8 @@ int fcntl_setfl(int fd, int flag);
#define STRTOSZ_DEFSUFFIX_B 'B' #define STRTOSZ_DEFSUFFIX_B 'B'
int64_t strtosz(const char *nptr, char **end); int64_t strtosz(const char *nptr, char **end);
int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix); int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix);
int64_t strtosz_suffix_unit(const char *nptr, char **end,
const char default_suffix, int64_t unit);
/* path.c */ /* path.c */
void init_paths(const char *prefix); void init_paths(const char *prefix);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册