From 5a744a9ca69e469fde2981bdc5feae27a1ac75f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Mon, 21 Nov 2011 17:16:38 -0800 Subject: [PATCH] add heim_string_create_with_bytes --- base/string.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/base/string.c b/base/string.c index 11e884115..b2ae18edb 100644 --- a/base/string.c +++ b/base/string.c @@ -79,12 +79,19 @@ struct heim_type_data _heim_string_object = { heim_string_t heim_string_create(const char *string) { - size_t len = strlen(string); + return heim_string_create_with_bytes(string, strlen(string)); +} + +heim_string_t +heim_string_create_with_bytes(const void *data, size_t len) +{ heim_string_t s; s = _heim_alloc_object(&_heim_string_object, len + 1); - if (s) - memcpy(s, string, len + 1); + if (s) { + memcpy(s, data, len); + ((char *)s)[len] = '\0'; + } return s; }