]> granicus.if.org Git - p11-kit/commitdiff
common: New p11_array_insert function
authorDaiki Ueno <dueno@redhat.com>
Tue, 8 Aug 2017 12:52:37 +0000 (14:52 +0200)
committerDaiki Ueno <ueno@gnu.org>
Tue, 8 Aug 2017 14:04:40 +0000 (16:04 +0200)
common/array.c
common/array.h

index 61244750a65a9c39db250dba6c83df023563ed17..42084f8921e55a3e4e860a80e126ae699aa92327 100644 (file)
@@ -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)
index 94be29c9efbf86dc77329580aac345fa98265943..212d533ca742930cc65b741192b2d653ae62d84f 100644 (file)
@@ -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);