Skip to content

Commit

Permalink
Implements chula_ahextol()
Browse files Browse the repository at this point in the history
  • Loading branch information
alobbs committed Dec 8, 2014
1 parent 1070f93 commit 0ffcebb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions libchula/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,30 @@ chula_atol (const char *str, long *ret_value)
return ret_ok;
}

ret_t
chula_ahextol (const char *str, long *ret_value)
{
long tmp;
char *endptr = NULL;

if (str == NULL) {
return ret_error;
}

errno = 0;
tmp = strtoul (str, &endptr, 16);
if (errno != 0) {
return ret_error;
}

if (str == endptr) {
/* No digits were found */
return ret_error;
}

*ret_value = tmp;
return ret_ok;
}

ret_t
chula_atob (const char *str, bool *ret_value)
Expand Down
1 change: 1 addition & 0 deletions libchula/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ char *chula_min_str (char *s1, char *s2);
char *chula_max_str (char *s1, char *s2);
ret_t chula_atoi (const char *str, int *ret_value);
ret_t chula_atol (const char *str, long *ret_value);
ret_t chula_ahextol (const char *str, long *ret_value);
ret_t chula_atob (const char *str, bool *ret_value);
int chula_string_is_ipv6 (chula_buffer_t *ip);
ret_t chula_malloc_size (const void *ptr, size_t *size);
Expand Down

0 comments on commit 0ffcebb

Please sign in to comment.