summaryrefslogtreecommitdiff
path: root/crypto/stack/stack.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/stack/stack.c')
-rw-r--r--crypto/stack/stack.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/crypto/stack/stack.c b/crypto/stack/stack.c
index 331f907190f7..de437acf6a5c 100644
--- a/crypto/stack/stack.c
+++ b/crypto/stack/stack.c
@@ -115,6 +115,40 @@ _STACK *sk_dup(_STACK *sk)
return (NULL);
}
+_STACK *sk_deep_copy(_STACK *sk, void *(*copy_func) (void *),
+ void (*free_func) (void *))
+{
+ _STACK *ret;
+ int i;
+
+ if ((ret = OPENSSL_malloc(sizeof(_STACK))) == NULL)
+ return ret;
+ ret->comp = sk->comp;
+ ret->sorted = sk->sorted;
+ ret->num = sk->num;
+ ret->num_alloc = sk->num > MIN_NODES ? sk->num : MIN_NODES;
+ ret->data = OPENSSL_malloc(sizeof(char *) * ret->num_alloc);
+ if (ret->data == NULL) {
+ OPENSSL_free(ret);
+ return NULL;
+ }
+ for (i = 0; i < ret->num_alloc; i++)
+ ret->data[i] = NULL;
+
+ for (i = 0; i < ret->num; ++i) {
+ if (sk->data[i] == NULL)
+ continue;
+ if ((ret->data[i] = copy_func(sk->data[i])) == NULL) {
+ while (--i >= 0)
+ if (ret->data[i] != NULL)
+ free_func(ret->data[i]);
+ sk_free(ret);
+ return NULL;
+ }
+ }
+ return ret;
+}
+
_STACK *sk_new_null(void)
{
return sk_new((int (*)(const void *, const void *))0);