Lines Matching refs:sk
95 size_t sk_num(const _STACK *sk) { in sk_num() argument
96 if (sk == NULL) { in sk_num()
99 return sk->num; in sk_num()
102 void sk_zero(_STACK *sk) { in sk_zero() argument
103 if (sk == NULL || sk->num == 0) { in sk_zero()
106 memset(sk->data, 0, sizeof(void*) * sk->num); in sk_zero()
107 sk->num = 0; in sk_zero()
108 sk->sorted = 0; in sk_zero()
111 void *sk_value(const _STACK *sk, size_t i) { in sk_value() argument
112 if (!sk || i >= sk->num) { in sk_value()
115 return sk->data[i]; in sk_value()
118 void *sk_set(_STACK *sk, size_t i, void *value) { in sk_set() argument
119 if (!sk || i >= sk->num) { in sk_set()
122 return sk->data[i] = value; in sk_set()
125 void sk_free(_STACK *sk) { in sk_free() argument
126 if (sk == NULL) { in sk_free()
129 OPENSSL_free(sk->data); in sk_free()
130 OPENSSL_free(sk); in sk_free()
133 void sk_pop_free(_STACK *sk, void (*func)(void *)) { in sk_pop_free() argument
136 if (sk == NULL) { in sk_pop_free()
140 for (i = 0; i < sk->num; i++) { in sk_pop_free()
141 if (sk->data[i] != NULL) { in sk_pop_free()
142 func(sk->data[i]); in sk_pop_free()
145 sk_free(sk); in sk_pop_free()
148 size_t sk_insert(_STACK *sk, void *p, size_t where) { in sk_insert() argument
149 if (sk == NULL) { in sk_insert()
153 if (sk->num_alloc <= sk->num + 1) { in sk_insert()
155 size_t new_alloc = sk->num_alloc << 1; in sk_insert()
160 if (new_alloc < sk->num_alloc || alloc_size / sizeof(void *) != new_alloc) { in sk_insert()
161 new_alloc = sk->num_alloc + 1; in sk_insert()
166 if (new_alloc < sk->num_alloc || alloc_size / sizeof(void *) != new_alloc) { in sk_insert()
170 data = OPENSSL_realloc(sk->data, alloc_size); in sk_insert()
175 sk->data = data; in sk_insert()
176 sk->num_alloc = new_alloc; in sk_insert()
179 if (where >= sk->num) { in sk_insert()
180 sk->data[sk->num] = p; in sk_insert()
182 memmove(&sk->data[where + 1], &sk->data[where], in sk_insert()
183 sizeof(void *) * (sk->num - where)); in sk_insert()
184 sk->data[where] = p; in sk_insert()
187 sk->num++; in sk_insert()
188 sk->sorted = 0; in sk_insert()
190 return sk->num; in sk_insert()
193 void *sk_delete(_STACK *sk, size_t where) { in sk_delete() argument
196 if (!sk || where >= sk->num) { in sk_delete()
200 ret = sk->data[where]; in sk_delete()
202 if (where != sk->num - 1) { in sk_delete()
203 memmove(&sk->data[where], &sk->data[where + 1], in sk_delete()
204 sizeof(void *) * (sk->num - where - 1)); in sk_delete()
207 sk->num--; in sk_delete()
211 void *sk_delete_ptr(_STACK *sk, void *p) { in sk_delete_ptr() argument
214 if (sk == NULL) { in sk_delete_ptr()
218 for (i = 0; i < sk->num; i++) { in sk_delete_ptr()
219 if (sk->data[i] == p) { in sk_delete_ptr()
220 return sk_delete(sk, i); in sk_delete_ptr()
227 int sk_find(_STACK *sk, size_t *out_index, void *p) { in sk_find() argument
232 if (sk == NULL) { in sk_find()
236 if (sk->comp == NULL) { in sk_find()
238 for (i = 0; i < sk->num; i++) { in sk_find()
239 if (sk->data[i] == p) { in sk_find()
253 sk_sort(sk); in sk_find()
260 comp_func=(int (*)(const void *,const void *))(sk->comp); in sk_find()
261 r = bsearch(&p, sk->data, sk->num, sizeof(void *), comp_func); in sk_find()
265 i = ((void **)r) - sk->data; in sk_find()
267 while (i > 0 && sk->comp((const void**) &p, (const void**) &sk->data[i-1]) == 0) { in sk_find()
276 void *sk_shift(_STACK *sk) { in sk_shift() argument
277 if (sk == NULL) { in sk_shift()
280 if (sk->num == 0) { in sk_shift()
283 return sk_delete(sk, 0); in sk_shift()
286 size_t sk_push(_STACK *sk, void *p) { return (sk_insert(sk, p, sk->num)); } in sk_push() argument
288 void *sk_pop(_STACK *sk) { in sk_pop() argument
289 if (sk == NULL) { in sk_pop()
292 if (sk->num == 0) { in sk_pop()
295 return sk_delete(sk, sk->num - 1); in sk_pop()
298 _STACK *sk_dup(const _STACK *sk) { in sk_dup() argument
302 if (sk == NULL) { in sk_dup()
306 ret = sk_new(sk->comp); in sk_dup()
311 s = (void **)OPENSSL_realloc(ret->data, sizeof(void *) * sk->num_alloc); in sk_dup()
317 ret->num = sk->num; in sk_dup()
318 memcpy(ret->data, sk->data, sizeof(void *) * sk->num); in sk_dup()
319 ret->sorted = sk->sorted; in sk_dup()
320 ret->num_alloc = sk->num_alloc; in sk_dup()
321 ret->comp = sk->comp; in sk_dup()
329 void sk_sort(_STACK *sk) { in sk_sort() argument
332 if (sk == NULL || sk->sorted) { in sk_sort()
337 comp_func = (int (*)(const void *, const void *))(sk->comp); in sk_sort()
338 qsort(sk->data, sk->num, sizeof(void *), comp_func); in sk_sort()
339 sk->sorted = 1; in sk_sort()
342 int sk_is_sorted(const _STACK *sk) { in sk_is_sorted() argument
343 if (!sk) { in sk_is_sorted()
346 return sk->sorted; in sk_is_sorted()
349 stack_cmp_func sk_set_cmp_func(_STACK *sk, stack_cmp_func comp) { in sk_set_cmp_func() argument
350 stack_cmp_func old = sk->comp; in sk_set_cmp_func()
352 if (sk->comp != comp) { in sk_set_cmp_func()
353 sk->sorted = 0; in sk_set_cmp_func()
355 sk->comp = comp; in sk_set_cmp_func()
360 _STACK *sk_deep_copy(const _STACK *sk, void *(*copy_func)(void *), in sk_deep_copy() argument
362 _STACK *ret = sk_dup(sk); in sk_deep_copy()