Commit 7f3c5874 authored by Lucas Russo's avatar Lucas Russo

hal/hal_utils/hal_utils.*: add numerify key functions

These are just convenient wrappers for standard C strtoul ()
function
parent 5dfa4ca5
......@@ -88,6 +88,21 @@ char *halutils_stringify_hex_key (uint32_t key)
return halutils_stringify_key (key, 16);
}
uint32_t halutils_numerify_key (const char *key, uint32_t base)
{
return strtoul (key, NULL, base);
}
uint32_t halutils_numerify_dec_key (const char *key)
{
return halutils_numerify_key (key, 10);
}
uint32_t halutils_numerify_hex_key (const char *key)
{
return halutils_numerify_key (key, 16);
}
#define SEPARATOR_BYTES 1
/* FIXME: poorly written */
static char *_halutils_concat_strings_raw (const char *str1, const char* str2,
......
......@@ -31,6 +31,18 @@ char *halutils_stringify_dec_key (uint32_t key);
/* Allocates a string with the necessary size to fit an hexadecimal key */
char *halutils_stringify_hex_key (uint32_t key);
/* Converts a key string into the specified numeric base. Must fit into
* a uint32_t */
uint32_t halutils_numerify_key (const char *key, uint32_t base);
/* Converts a key string into the decimal base. Result must fit into
* a uint32_t */
uint32_t halutils_numerify_dec_key (const char *key);
/* Converts a key string into the hexadecimal base. Result must fit into
* a uint32_t */
uint32_t halutils_numerify_hex_key (const char *key);
/* Concatenates 2 strings togheter with a separator. returns the string if
* OK, NULL in case of error */
char *halutils_concat_strings (const char *str1, const char* str2, char sep);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment