diff options
author | Daiki Ueno <dueno@redhat.com> | 2017-08-08 14:52:37 +0200 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2017-08-08 16:04:40 +0200 |
commit | c29f51ad8ef97a1fae356dd7660e41d81cde0d09 (patch) | |
tree | 9d1805be9fa0b76119fc31ca63e464c1c5f5835c /common | |
parent | a860db364521ca6e9046bbf60fbbb1ca2bc08711 (diff) |
common: New p11_array_insert function
Diffstat (limited to 'common')
-rw-r--r-- | common/array.c | 16 | ||||
-rw-r--r-- | common/array.h | 4 |
2 files changed, 20 insertions, 0 deletions
diff --git a/common/array.c b/common/array.c index 6124475..42084f8 100644 --- a/common/array.c +++ b/common/array.c @@ -107,6 +107,22 @@ p11_array_push (p11_array *array, return true; } +bool +p11_array_insert (p11_array *array, + unsigned int index, + void *value) +{ + return_val_if_fail (index <= array->num, false); + if (!maybe_expand_array (array, array->num + 1)) + return_val_if_reached (false); + + memmove (array->elem + index + 1, array->elem + index, + (array->num - index) * sizeof (void*)); + array->elem[index] = value; + array->num++; + return true; +} + void p11_array_remove (p11_array *array, unsigned int index) diff --git a/common/array.h b/common/array.h index 94be29c..212d533 100644 --- a/common/array.h +++ b/common/array.h @@ -60,6 +60,10 @@ void p11_array_free (p11_array *array); bool p11_array_push (p11_array *array, void *value); +bool p11_array_insert (p11_array *array, + unsigned int index, + void *value); + void p11_array_remove (p11_array *array, unsigned int index); |