X-Git-Url: http://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Futils.c;h=134d2054fbde1ea74de3a8562c93c13067bfcf53;hp=bd61fff3d52ad8c6c16d68b0ca9e195009225018;hb=240baf2b88e34c1600aa2d11a1f1d9a11af4893f;hpb=0c4e727b6aeb61a5fd2749abede3c9b56f84504c diff --git a/src/common/utils.c b/src/common/utils.c index bd61fff3d..134d2054f 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -1669,3 +1669,39 @@ end: free(buf); return ret_val; } + +LTTNG_HIDDEN +int utils_parse_unsigned_long_long(const char *str, + unsigned long long *value) +{ + int ret; + char *endptr; + + assert(str); + assert(value); + + errno = 0; + *value = strtoull(str, &endptr, 10); + + /* Conversion failed. Out of range? */ + if (errno != 0) { + /* Don't print an error; allow the caller to log a better error. */ + DBG("Failed to parse string as unsigned long long number: string = '%s', errno = %d", + str, errno); + ret = -1; + goto end; + } + + /* Not the end of the string or empty string. */ + if (*endptr || endptr == str) { + DBG("Failed to parse string as unsigned long long number: string = '%s'", + str); + ret = -1; + goto end; + } + + ret = 0; + +end: + return ret; +}