btstack_util: extend btstack_strcpy to return bytes copied

This commit is contained in:
Milanka Ringwald 2022-03-21 11:34:49 +01:00 committed by Matthias Ringwald
parent f819d1d921
commit ed7a067cb2
2 changed files with 7 additions and 5 deletions

View File

@ -546,10 +546,11 @@ uint16_t btstack_next_cid_ignoring_zero(uint16_t current_cid){
return next_cid;
}
void btstack_strcpy(char * dst, uint16_t dst_size, const char * src){
uint16_t bytes_to_copy = (uint16_t) btstack_min( dst_size - 1, (uint32_t) strlen(src));
uint16_t btstack_strcpy(char * dst, uint16_t dst_size, const char * src){
uint16_t bytes_to_copy = btstack_min( dst_size - 1, strlen(src));
(void) memcpy(dst, src, bytes_to_copy);
dst[bytes_to_copy] = 0;
dst[dst_size-1] = 0;
return bytes_to_copy + 1;
}
void btstack_strcat(char * dst, uint16_t dst_size, const char * src){
@ -593,4 +594,4 @@ uint16_t btstack_virtual_memcpy(
memcpy(&buffer[(field_offset + skip_at_start) - buffer_offset], &field_data[skip_at_start], bytes_to_copy);
return bytes_to_copy;
}
}

View File

@ -322,8 +322,9 @@ uint16_t btstack_next_cid_ignoring_zero(uint16_t current_cid);
* @param dst
* @param dst_size
* @param src
* @retun bytes_copied including trailing 0
*/
void btstack_strcpy(char * dst, uint16_t dst_size, const char * src);
uint16_t btstack_strcpy(char * dst, uint16_t dst_size, const char * src);
/**
* @brief Append src string to string in dst buffer with terminating '\0'