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;
+}
enum lttng_error_code utils_group_id_from_name(
const char *group_name, gid_t *group_id);
+/*
+ * Parse `str` as an unsigned long long value.
+ *
+ * Return 0 on success. Return -1 on failure which can be because:
+ *
+ * - `str` is zero length
+ * - `str` contains invalid
+ */
+LTTNG_HIDDEN
+int utils_parse_unsigned_long_long(const char *str,
+ unsigned long long *value);
+
#endif /* _COMMON_UTILS_H */