build: Eliminate cutils/str_parms dependency from system/bt
Eliminate cutils/str_parmss dependency from system/bt by adding osi_str_parms:
- Added hash_map_utils which implements partial functions of cutils/str_parms
and uses osi/hash_map instead of cutils/hashmap.
- Updated osi/Android.mk, osi/BUILD.gn and the includes in audio_a2dp to use
osi_str_parms.
- Added unittest for hash_map_utils.
Bug: 21957864
Change-Id: I8458d9e45df6cab2b71840d24d17b9d75de9842c
diff --git a/osi/src/allocator.c b/osi/src/allocator.c
index 7ebeb5e..ceb1618 100644
--- a/osi/src/allocator.c
+++ b/osi/src/allocator.c
@@ -15,7 +15,6 @@
* limitations under the License.
*
******************************************************************************/
-
#include <stdlib.h>
#include <string.h>
@@ -29,9 +28,9 @@
size_t real_size = allocation_tracker_resize_for_canary(size);
char *new_string = allocation_tracker_notify_alloc(
- alloc_allocator_id,
- malloc(real_size),
- size);
+ alloc_allocator_id,
+ malloc(real_size),
+ size);
if (!new_string)
return NULL;
@@ -39,6 +38,25 @@
return new_string;
}
+char *osi_strndup(const char *str, size_t len) {
+ size_t size = strlen(str);
+ if (len < size)
+ size = len;
+
+ size_t real_size = allocation_tracker_resize_for_canary(size + 1);
+
+ char *new_string = allocation_tracker_notify_alloc(
+ alloc_allocator_id,
+ malloc(real_size),
+ size + 1);
+ if (!new_string)
+ return NULL;
+
+ memcpy(new_string, str, size);
+ new_string[size] = '\0';
+ return new_string;
+}
+
void *osi_malloc(size_t size) {
size_t real_size = allocation_tracker_resize_for_canary(size);
return allocation_tracker_notify_alloc(