diff options
author | Daniel Black <daniel@linux.vnet.ibm.com> | 2017-12-05 12:39:37 +1100 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2017-12-19 13:40:05 +0400 |
commit | 3464b670257e954cd6ee88c95da7b4a217d0ea82 (patch) | |
tree | 35ccc332ff1c681dccbf89990f64dc56c6088482 /mysys | |
parent | 22f2b39c147a46193c5a616a8df84d78ce3db99c (diff) | |
download | mariadb-git-3464b670257e954cd6ee88c95da7b4a217d0ea82.tar.gz |
mysys: handle T, P, E suffixs
Signed-off-by: Daniel Black <daniel@linux.vnet.ibm.com>
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/my_getopt.c | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index c9bfe2e1eaa..0ea062988f6 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -969,31 +969,43 @@ my_bool getopt_compare_strings(register const char *s, register const char *t, /* function: eval_num_suffix - Transforms suffix like k/m/g to their real value. + Transforms suffix like k/m/g/t/p/e to their real value. */ -static inline long eval_num_suffix(char *suffix, int *error) +static inline ulonglong eval_num_suffix(char *suffix, int *error) { - long num= 1; - if (*suffix == 'k' || *suffix == 'K') - num*= 1024L; - else if (*suffix == 'm' || *suffix == 'M') - num*= 1024L * 1024L; - else if (*suffix == 'g' || *suffix == 'G') - num*= 1024L * 1024L * 1024L; - else if (*suffix) - { + switch (*suffix) { + case '\0': + return 1ULL; + case 'k': + case 'K': + return 1ULL << 10; + case 'm': + case 'M': + return 1ULL << 20; + case 'g': + case 'G': + return 1ULL << 30; + case 't': + case 'T': + return 1ULL << 40; + case 'p': + case 'P': + return 1ULL << 50; + case 'e': + case 'E': + return 1ULL << 60; + default: *error= 1; - return 0; + return 0ULL; } - return num; } /* function: eval_num_suffix_ll Transforms a number with a suffix to real number. Suffix can - be k|K for kilo, m|M for mega or g|G for giga. + be k|K for kilo, m|M for mega, etc. */ static longlong eval_num_suffix_ll(char *argument, @@ -1026,7 +1038,7 @@ static longlong eval_num_suffix_ll(char *argument, function: eval_num_suffix_ull Transforms a number with a suffix to positive Integer. Suffix can - be k|K for kilo, m|M for mega or g|G for giga. + be k|K for kilo, m|M for mega, etc. */ static ulonglong eval_num_suffix_ull(char *argument, |