Add safe_atoull()

This commit is contained in:
Ace Jones 2010-01-10 12:09:29 +01:00 committed by Julien BLACHE
parent 5867821ed7
commit e948f69d0d
2 changed files with 31 additions and 0 deletions

View File

@ -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)
{

View File

@ -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);