btstack_util: add btstack_strcpy

This commit is contained in:
Matthias Ringwald 2022-01-17 15:33:52 +01:00
parent 09f429629a
commit de22414a4c
2 changed files with 15 additions and 0 deletions

View File

@ -489,3 +489,9 @@ 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 = btstack_min( dst_size - 1, strlen(src));
(void) memcpy(dst, src, bytes_to_copy);
dst[dst_size-1] = 0;
}

View File

@ -302,6 +302,15 @@ uint8_t btstack_crc8_calc(uint8_t * data, uint16_t len);
*/
uint16_t btstack_next_cid_ignoring_zero(uint16_t current_cid);
/**
* @brief Copy string (up to dst_size-1 characters) from src into dst buffer with terminating '\0'
* @note replaces strncpy + dst[dst_size-1] = '\0'
* @param dst
* @param dst_size
* @param src
*/
void btstack_strcpy(char * dst, uint16_t dst_size, const char * src);
/* API_END */
#if defined __cplusplus