[waffle] [PATCH 07/11] core: Add func wcore_attrib_list_copy()
Chad Versace
chad.versace at linux.intel.com
Tue Dec 16 00:18:31 PST 2014
This is useful for making a writable copy of a read-only attribute list.
Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
src/waffle/core/wcore_attrib_list.c | 19 +++++++++++++++++++
src/waffle/core/wcore_attrib_list.h | 3 +++
2 files changed, 22 insertions(+)
diff --git a/src/waffle/core/wcore_attrib_list.c b/src/waffle/core/wcore_attrib_list.c
index a7f087d..94013b9 100644
--- a/src/waffle/core/wcore_attrib_list.c
+++ b/src/waffle/core/wcore_attrib_list.c
@@ -28,6 +28,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
+#include <string.h>
size_t
wcore_attrib_list_length(const intptr_t attrib_list[])
@@ -43,6 +44,24 @@ wcore_attrib_list_length(const intptr_t attrib_list[])
return (i - attrib_list) / 2;
}
+intptr_t*
+wcore_attrib_list_copy(const intptr_t attrib_list[])
+{
+ intptr_t *copy;
+
+ if (attrib_list) {
+ size_t length = wcore_attrib_list_length(attrib_list);
+ intptr_t size = (2 * length + 1) * sizeof(intptr_t);
+ copy = malloc(size);
+ memcpy(copy, attrib_list, size);
+ } else {
+ copy = malloc(sizeof(intptr_t));
+ copy[0] = 0;
+ }
+
+ return copy;
+}
+
bool
wcore_attrib_list_get(
const intptr_t *attrib_list,
diff --git a/src/waffle/core/wcore_attrib_list.h b/src/waffle/core/wcore_attrib_list.h
index 5e6473b..bd1179d 100644
--- a/src/waffle/core/wcore_attrib_list.h
+++ b/src/waffle/core/wcore_attrib_list.h
@@ -32,6 +32,9 @@
size_t
wcore_attrib_list_length(const intptr_t attrib_list[]);
+intptr_t*
+wcore_attrib_list_copy(const intptr_t attrib_list[]);
+
bool
wcore_attrib_list_get(
const intptr_t *attrib_list,
--
2.2.0
More information about the waffle
mailing list