Commit 96703bd4 authored by Lucas Russo's avatar Lucas Russo

hal/hal_utils/*: add new concat function

The new function can concatenate two null terminated
C strings with a character separator inbetween.
parent 4e66afa1
......@@ -84,3 +84,17 @@ char *halutils_stringify_hex_key (uint32_t key)
{
return halutils_stringify_key (key, 16);
}
#define SEPARATOR_BYTES 1
char *halutils_concat_strings (const char *str1, const char* str2, char sep)
{
char *str = zmalloc (strlen(str1) + strlen(str2) +
SEPARATOR_BYTES /* separator length */+ 1 /* \0 */);
ASSERT_ALLOC(str, err_str_alloc);
sprintf (str, "%s%c%s", str1, sep, str2);
return str;
err_str_alloc:
return NULL;
}
......@@ -31,4 +31,8 @@ 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);
/* 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);
#endif
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