diff options
author | Joerg Roedel <joerg.roedel@amd.com> | 2011-07-07 16:13:11 +0200 |
---|---|---|
committer | Marcelo Tosatti <mtosatti@redhat.com> | 2011-08-05 12:04:27 -0300 |
commit | a732e1baa864d5b10c5cfd9e3e437563b771c1a8 (patch) | |
tree | 8de5136d1a0cda612d757952f0a804b851ade64a /cutils.c | |
parent | 2a1ac12b0bb29054f5fbc8144c800ca7634c0658 (diff) |
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: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'cutils.c')
-rw-r--r-- | cutils.c | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -322,7 +322,8 @@ int fcntl_setfl(int fd, int flag) * value must be terminated by whitespace, ',' or '\0'. Return -1 on * 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; char *endptr; @@ -362,20 +363,20 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) } break; case STRTOSZ_DEFSUFFIX_KB: - mul = 1 << 10; + mul = unit; break; case 0: if (mul_required) { goto fail; } case STRTOSZ_DEFSUFFIX_MB: - mul = 1ULL << 20; + mul = unit * unit; break; case STRTOSZ_DEFSUFFIX_GB: - mul = 1ULL << 30; + mul = unit * unit * unit; break; case STRTOSZ_DEFSUFFIX_TB: - mul = 1ULL << 40; + mul = unit * unit * unit * unit; break; default: goto fail; @@ -405,6 +406,11 @@ fail: 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) { return strtosz_suffix(nptr, end, STRTOSZ_DEFSUFFIX_MB); |