diff --git a/src/misc.c b/src/misc.c index 0cadf30c..185c8a05 100644 --- a/src/misc.c +++ b/src/misc.c @@ -102,6 +102,34 @@ safe_atol(const char *str, long *val) return 0; } +int +safe_atoull(const char *str, unsigned long long *val) +{ + char *end; + unsigned long long intval; + + errno = 0; + intval = strtoull(str, &end, 10); + + if (errno) + { + DPRINTF(E_DBG, L_MISC, "Invalid unsigned long long integer in string (%s): %s\n", str, strerror(errno)); + + return -1; + } + + if (end == str) + { + DPRINTF(E_DBG, L_MISC, "No unsigned long long integer found in string (%s)\n", str); + + return -1; + } + + *val = intval; + + return 0; +} + char * m_realpath(const char *pathname) { diff --git a/src/misc.h b/src/misc.h index 5aea3518..e48b308a 100644 --- a/src/misc.h +++ b/src/misc.h @@ -10,6 +10,9 @@ safe_atoi(const char *str, int *val); int safe_atol(const char *str, long *val); +int +safe_atoull(const char *str, unsigned long long *val); + char * m_realpath(const char *pathname);