From 3ece47889a4dbd35fb7c3341a636bf5dfe1a37cf Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 29 Apr 2022 11:20:12 +0200 Subject: [PATCH] btstack_util: add btstack_strcat --- src/btstack_util.c | 8 ++++++++ src/btstack_util.h | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/src/btstack_util.c b/src/btstack_util.c index 328302a00..869160550 100644 --- a/src/btstack_util.c +++ b/src/btstack_util.c @@ -499,3 +499,11 @@ void btstack_strcpy(char * dst, uint16_t dst_size, const char * src){ (void) memcpy(dst, src, bytes_to_copy); dst[bytes_to_copy] = 0; } + +void btstack_strcat(char * dst, uint16_t dst_size, const char * src){ + uint16_t src_len = (uint16_t) strlen(src); + uint16_t dst_len = (uint16_t) strlen(dst); + uint16_t bytes_to_copy = btstack_min( src_len, dst_size - dst_len - 1); + (void) memcpy( &dst[dst_len], src, bytes_to_copy); + dst[dst_len + bytes_to_copy] = 0; +} diff --git a/src/btstack_util.h b/src/btstack_util.h index 653ef2576..91b87b908 100644 --- a/src/btstack_util.h +++ b/src/btstack_util.h @@ -319,6 +319,15 @@ uint16_t btstack_next_cid_ignoring_zero(uint16_t current_cid); */ void btstack_strcpy(char * dst, uint16_t dst_size, const char * src); +/** + * @brief Append src string to string in dst buffer with terminating '\0' + * @note max total string length will be dst_size-1 characters + * @param dst + * @param dst_size + * @param src + */ +void btstack_strcat(char * dst, uint16_t dst_size, const char * src); + /* API_END */ #if defined __cplusplus