diff options
author | Andrew Bartlett <abartlet@samba.org> | 2011-04-30 12:52:11 +1000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2011-04-30 05:58:35 +0200 |
commit | 1018dd182686f5b3a6db3d08294c78305521e4f4 (patch) | |
tree | fa495ea3983e9e4a20685c76a6d070562b1da3f9 /source3/lib | |
parent | e1eae822856c076f63874d8d3b07691b3154848d (diff) | |
download | samba-1018dd182686f5b3a6db3d08294c78305521e4f4.tar.gz samba-1018dd182686f5b3a6db3d08294c78305521e4f4.tar.bz2 samba-1018dd182686f5b3a6db3d08294c78305521e4f4.zip |
s3-lib: Rely on uint64_t in conv_str_size()
Autobuild-User: Andrew Bartlett <abartlet@samba.org>
Autobuild-Date: Sat Apr 30 05:58:35 CEST 2011 on sn-devel-104
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/util_str.c | 43 |
1 files changed, 13 insertions, 30 deletions
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 07a058925d..b15dd7907b 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -1206,25 +1206,17 @@ uint64_t STR_TO_SMB_BIG_UINT(const char *nptr, const char **entptr) * * Returns 0 if the string can't be converted. */ -SMB_OFF_T conv_str_size(const char * str) +uint64_t conv_str_size(const char * str) { - SMB_OFF_T lval_orig; - SMB_OFF_T lval; + uint64_t lval_orig; + uint64_t lval; char * end; if (str == NULL || *str == '\0') { return 0; } -#ifdef HAVE_STRTOULL - if (sizeof(SMB_OFF_T) == 8) { - lval = strtoull(str, &end, 10 /* base */); - } else { - lval = strtoul(str, &end, 10 /* base */); - } -#else - lval = strtoul(str, &end, 10 /* base */); -#endif + lval = strtoull(str, &end, 10 /* base */); if (end == NULL || end == str) { return 0; @@ -1237,32 +1229,23 @@ SMB_OFF_T conv_str_size(const char * str) lval_orig = lval; if (strwicmp(end, "K") == 0) { - lval *= (SMB_OFF_T)1024; + lval *= 1024ULL; } else if (strwicmp(end, "M") == 0) { - lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024); + lval *= (1024ULL * 1024ULL); } else if (strwicmp(end, "G") == 0) { - lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * - (SMB_OFF_T)1024); + lval *= (1024ULL * 1024ULL * + 1024ULL); } else if (strwicmp(end, "T") == 0) { - lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * - (SMB_OFF_T)1024 * (SMB_OFF_T)1024); + lval *= (1024ULL * 1024ULL * + 1024ULL * 1024ULL); } else if (strwicmp(end, "P") == 0) { - lval *= ((SMB_OFF_T)1024 * (SMB_OFF_T)1024 * - (SMB_OFF_T)1024 * (SMB_OFF_T)1024 * - (SMB_OFF_T)1024); + lval *= (1024ULL * 1024ULL * + 1024ULL * 1024ULL * + 1024ULL); } else { return 0; } - /* - * Primitive attempt to detect wrapping on platforms with - * 4-byte SMB_OFF_T. It's better to let the caller handle a - * failure than some random number. - */ - if (lval_orig <= lval) { - return 0; - } - return lval; } |