diff options
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); |