Lines Matching refs:st
177 static int sk_reserve(OPENSSL_STACK *st, int n, int exact) in sk_reserve() argument
183 if (n > max_nodes - st->num) { in sk_reserve()
189 num_alloc = st->num + n; in sk_reserve()
194 if (st->data == NULL) { in sk_reserve()
199 if ((st->data = OPENSSL_zalloc(sizeof(void *) * num_alloc)) == NULL) in sk_reserve()
201 st->num_alloc = num_alloc; in sk_reserve()
206 if (num_alloc <= st->num_alloc) in sk_reserve()
208 num_alloc = compute_growth(num_alloc, st->num_alloc); in sk_reserve()
213 } else if (num_alloc == st->num_alloc) { in sk_reserve()
217 tmpdata = OPENSSL_realloc((void *)st->data, sizeof(void *) * num_alloc); in sk_reserve()
221 st->data = tmpdata; in sk_reserve()
222 st->num_alloc = num_alloc; in sk_reserve()
228 OPENSSL_STACK *st = OPENSSL_zalloc(sizeof(OPENSSL_STACK)); in OPENSSL_sk_new_reserve() local
230 if (st == NULL) in OPENSSL_sk_new_reserve()
233 st->comp = c; in OPENSSL_sk_new_reserve()
236 return st; in OPENSSL_sk_new_reserve()
238 if (!sk_reserve(st, n, 1)) { in OPENSSL_sk_new_reserve()
239 OPENSSL_sk_free(st); in OPENSSL_sk_new_reserve()
243 return st; in OPENSSL_sk_new_reserve()
246 int OPENSSL_sk_reserve(OPENSSL_STACK *st, int n) in OPENSSL_sk_reserve() argument
248 if (st == NULL) { in OPENSSL_sk_reserve()
255 return sk_reserve(st, n, 1); in OPENSSL_sk_reserve()
258 int OPENSSL_sk_insert(OPENSSL_STACK *st, const void *data, int loc) in OPENSSL_sk_insert() argument
260 if (st == NULL) { in OPENSSL_sk_insert()
264 if (st->num == max_nodes) { in OPENSSL_sk_insert()
269 if (!sk_reserve(st, 1, 0)) in OPENSSL_sk_insert()
272 if ((loc >= st->num) || (loc < 0)) { in OPENSSL_sk_insert()
273 st->data[st->num] = data; in OPENSSL_sk_insert()
275 memmove(&st->data[loc + 1], &st->data[loc], in OPENSSL_sk_insert()
276 sizeof(st->data[0]) * (st->num - loc)); in OPENSSL_sk_insert()
277 st->data[loc] = data; in OPENSSL_sk_insert()
279 st->num++; in OPENSSL_sk_insert()
280 st->sorted = 0; in OPENSSL_sk_insert()
281 return st->num; in OPENSSL_sk_insert()
284 static ossl_inline void *internal_delete(OPENSSL_STACK *st, int loc) in internal_delete() argument
286 const void *ret = st->data[loc]; in internal_delete()
288 if (loc != st->num - 1) in internal_delete()
289 memmove(&st->data[loc], &st->data[loc + 1], in internal_delete()
290 sizeof(st->data[0]) * (st->num - loc - 1)); in internal_delete()
291 st->num--; in internal_delete()
296 void *OPENSSL_sk_delete_ptr(OPENSSL_STACK *st, const void *p) in OPENSSL_sk_delete_ptr() argument
300 if (st == NULL) in OPENSSL_sk_delete_ptr()
303 for (i = 0; i < st->num; i++) in OPENSSL_sk_delete_ptr()
304 if (st->data[i] == p) in OPENSSL_sk_delete_ptr()
305 return internal_delete(st, i); in OPENSSL_sk_delete_ptr()
309 void *OPENSSL_sk_delete(OPENSSL_STACK *st, int loc) in OPENSSL_sk_delete() argument
311 if (st == NULL || loc < 0 || loc >= st->num) in OPENSSL_sk_delete()
314 return internal_delete(st, loc); in OPENSSL_sk_delete()
317 static int internal_find(OPENSSL_STACK *st, const void *data, in internal_find() argument
324 if (st == NULL || st->num == 0) in internal_find()
330 if (st->comp == NULL) { in internal_find()
331 for (i = 0; i < st->num; i++) in internal_find()
332 if (st->data[i] == data) { in internal_find()
343 if (!st->sorted) { in internal_find()
346 for (i = 0; i < st->num; i++) in internal_find()
347 if (st->comp(&data, st->data + i) == 0) { in internal_find()
362 r = ossl_bsearch(&data, st->data, st->num, sizeof(void *), st->comp, in internal_find()
370 while (p < st->data + st->num) { in internal_find()
371 if (st->comp(&data, p) != 0) in internal_find()
379 return r == NULL ? -1 : (int)((const void **)r - st->data); in internal_find()
382 int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data) in OPENSSL_sk_find() argument
384 return internal_find(st, data, OSSL_BSEARCH_FIRST_VALUE_ON_MATCH, NULL); in OPENSSL_sk_find()
387 int OPENSSL_sk_find_ex(OPENSSL_STACK *st, const void *data) in OPENSSL_sk_find_ex() argument
389 return internal_find(st, data, OSSL_BSEARCH_VALUE_ON_NOMATCH, NULL); in OPENSSL_sk_find_ex()
392 int OPENSSL_sk_find_all(OPENSSL_STACK *st, const void *data, int *pnum) in OPENSSL_sk_find_all() argument
394 return internal_find(st, data, OSSL_BSEARCH_FIRST_VALUE_ON_MATCH, pnum); in OPENSSL_sk_find_all()
397 int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data) in OPENSSL_sk_push() argument
399 if (st == NULL) in OPENSSL_sk_push()
401 return OPENSSL_sk_insert(st, data, st->num); in OPENSSL_sk_push()
404 int OPENSSL_sk_unshift(OPENSSL_STACK *st, const void *data) in OPENSSL_sk_unshift() argument
406 return OPENSSL_sk_insert(st, data, 0); in OPENSSL_sk_unshift()
409 void *OPENSSL_sk_shift(OPENSSL_STACK *st) in OPENSSL_sk_shift() argument
411 if (st == NULL || st->num == 0) in OPENSSL_sk_shift()
413 return internal_delete(st, 0); in OPENSSL_sk_shift()
416 void *OPENSSL_sk_pop(OPENSSL_STACK *st) in OPENSSL_sk_pop() argument
418 if (st == NULL || st->num == 0) in OPENSSL_sk_pop()
420 return internal_delete(st, st->num - 1); in OPENSSL_sk_pop()
423 void OPENSSL_sk_zero(OPENSSL_STACK *st) in OPENSSL_sk_zero() argument
425 if (st == NULL || st->num == 0) in OPENSSL_sk_zero()
427 memset(st->data, 0, sizeof(*st->data) * st->num); in OPENSSL_sk_zero()
428 st->num = 0; in OPENSSL_sk_zero()
431 void OPENSSL_sk_pop_free(OPENSSL_STACK *st, OPENSSL_sk_freefunc func) in OPENSSL_sk_pop_free() argument
435 if (st == NULL) in OPENSSL_sk_pop_free()
437 for (i = 0; i < st->num; i++) in OPENSSL_sk_pop_free()
438 if (st->data[i] != NULL) in OPENSSL_sk_pop_free()
439 func((char *)st->data[i]); in OPENSSL_sk_pop_free()
440 OPENSSL_sk_free(st); in OPENSSL_sk_pop_free()
443 void OPENSSL_sk_free(OPENSSL_STACK *st) in OPENSSL_sk_free() argument
445 if (st == NULL) in OPENSSL_sk_free()
447 OPENSSL_free(st->data); in OPENSSL_sk_free()
448 OPENSSL_free(st); in OPENSSL_sk_free()
451 int OPENSSL_sk_num(const OPENSSL_STACK *st) in OPENSSL_sk_num() argument
453 return st == NULL ? -1 : st->num; in OPENSSL_sk_num()
456 void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i) in OPENSSL_sk_value() argument
458 if (st == NULL || i < 0 || i >= st->num) in OPENSSL_sk_value()
460 return (void *)st->data[i]; in OPENSSL_sk_value()
463 void *OPENSSL_sk_set(OPENSSL_STACK *st, int i, const void *data) in OPENSSL_sk_set() argument
465 if (st == NULL) { in OPENSSL_sk_set()
469 if (i < 0 || i >= st->num) { in OPENSSL_sk_set()
474 st->data[i] = data; in OPENSSL_sk_set()
475 st->sorted = 0; in OPENSSL_sk_set()
476 return (void *)st->data[i]; in OPENSSL_sk_set()
479 void OPENSSL_sk_sort(OPENSSL_STACK *st) in OPENSSL_sk_sort() argument
481 if (st != NULL && !st->sorted && st->comp != NULL) { in OPENSSL_sk_sort()
482 if (st->num > 1) in OPENSSL_sk_sort()
483 qsort(st->data, st->num, sizeof(void *), st->comp); in OPENSSL_sk_sort()
484 st->sorted = 1; /* empty or single-element stack is considered sorted */ in OPENSSL_sk_sort()
488 int OPENSSL_sk_is_sorted(const OPENSSL_STACK *st) in OPENSSL_sk_is_sorted() argument
490 return st == NULL ? 1 : st->sorted; in OPENSSL_sk_is_sorted()