diff options
author | Chad Versace <chad.versace@intel.com> | 2015-01-04 13:36:30 -0800 |
---|---|---|
committer | Chad Versace <chad.versace@intel.com> | 2015-01-27 09:36:06 -0800 |
commit | 7a052775c53eeeab65ae004b522c71f46c1a70f5 (patch) | |
tree | 54ee088b5ac5c36d77add36363166848e7dbc05b | |
parent | 73227a1162a531705463fb5a9a4e927542c86c5a (diff) |
core: Add func wcore_attrib_list_copy()
This is useful for making a writable copy of a read-only attribute list.
Signed-off-by: Chad Versace <chad.versace@intel.com>
Tested-by: Emil Velikov <emil.l.velikov@gmail.com> (msvc/wgl)
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
-rw-r--r-- | src/waffle/core/wcore_attrib_list.c | 37 | ||||
-rw-r--r-- | src/waffle/core/wcore_attrib_list.h | 3 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/waffle/core/wcore_attrib_list.c b/src/waffle/core/wcore_attrib_list.c index 0c447c0..6446ca0 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> #include "wcore_error.h" #include "wcore_util.h" @@ -167,3 +168,39 @@ wcore_attrib_list_from_int32(const int32_t attrib_list32[]) return attrib_list; } + +intptr_t* +wcore_attrib_list_copy(const intptr_t attrib_list[]) +{ + intptr_t *copy = NULL; + + if (attrib_list) { + size_t len; + size_t size = 0; + + len = wcore_attrib_list_length(attrib_list); + + if (!wcore_attrib_list_get_size(&size, len)) { + // Arithmetic overflow occurred, therefore we can't allocate the + // memory. + wcore_error(WAFFLE_ERROR_BAD_ALLOC); + return NULL; + } + + copy = wcore_malloc(size); + if (!copy) { + return NULL; + } + + memcpy(copy, attrib_list, size); + } else { + copy = wcore_malloc(sizeof(intptr_t)); + if (!copy) { + return NULL; + } + + copy[0] = 0; + } + + return copy; +} diff --git a/src/waffle/core/wcore_attrib_list.h b/src/waffle/core/wcore_attrib_list.h index 7a6aa2b..d4a771b 100644 --- a/src/waffle/core/wcore_attrib_list.h +++ b/src/waffle/core/wcore_attrib_list.h @@ -37,6 +37,9 @@ wcore_attrib_list_from_int32(const int32_t attrib_list[]); 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, |