Standard preamble:
========================================================================
..
.... Set up some character translations and predefined strings. \*(-- will
give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
double quote, and \*(R" will give a right double quote. \*(C+ will
give a nicer C++. Capital omega is used to do unbreakable dashes and
therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
nothing in troff, for use with C<>.
.tr \(*W- . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\}
Escape single quotes in literal strings from groff's Unicode transform.
If the F register is >0, we'll generate index entries on stderr for
titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
entries marked with X<> in POD. Of course, you'll have to process the
output yourself in some meaningful fashion.
Avoid warning from groff about undefined register 'F'.
.. .nr rF 0 . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] .\} . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents . \" corrections for vroff . \" for low resolution devices (crt and lpr) \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} ========================================================================
Title "DEFINE_STACK_OF 3ossl"
way too many mistakes in technical documents.
The \s-1STACK_OF\s0() macro returns the name for a stack of the specified \f(BI\s-1TYPE\s0. This is an opaque pointer to a structure declaration. This can be used in every header file that references the stack. There are several \s-1DEFINE...\s0 macros that create static inline functions for all of the functions described on this page. This should normally be used in one source file, and the stack manipulation is wrapped with application-specific functions.
\s-1DEFINE_STACK_OF\s0() creates set of functions for a stack of \f(BI\s-1TYPE\s0 elements. The type is referenced by \fB\s-1STACK_OF\s0(\f(BI\s-1TYPE\s0) and each function name begins with sk_\f(BI\s-1TYPE\s0_. \s-1DEFINE_STACK_OF_CONST\s0() is identical to \s-1DEFINE_STACK_OF\s0() except each element is constant.
.Vb 4 /* DEFINE_STACK_OF(TYPE) */ TYPE *sk_TYPE_value(STACK_OF(TYPE) *sk, int idx); /* DEFINE_STACK_OF_CONST(TYPE) */ const TYPE *sk_TYPE_value(STACK_OF(TYPE) *sk, int idx); .Ve
\s-1DEFINE_SPECIAL_STACK_OF\s0() and \s-1DEFINE_SPECIAL_STACK_OF_CONST\s0() are similar except \s-1FUNCNAME\s0 is used in the function names:
.Vb 4 /* DEFINE_SPECIAL_STACK_OF(TYPE, FUNCNAME) */ TYPE *sk_FUNCNAME_value(STACK_OF(TYPE) *sk, int idx); /* DEFINE_SPECIAL_STACK_OF(TYPE, FUNCNAME) */ const TYPE *sk_FUNCNAME_value(STACK_OF(TYPE) *sk, int idx); .Ve
\fBsk_\f(BI\s-1TYPE\s0_num() returns the number of elements in sk or -1 if sk is \s-1NULL.\s0
\fBsk_\f(BI\s-1TYPE\s0_value() returns element idx in sk, where idx starts at zero. If idx is out of range then \s-1NULL\s0 is returned.
\fBsk_\f(BI\s-1TYPE\s0_new() allocates a new empty stack using comparison function \fIcompare. If compare is \s-1NULL\s0 then no comparison function is used. This function is equivalent to sk_\f(BI\s-1TYPE\s0_new_reserve(compare, 0).
\fBsk_\f(BI\s-1TYPE\s0_new_null() allocates a new empty stack with no comparison function. This function is equivalent to sk_\f(BI\s-1TYPE\s0_new_reserve(\s-1NULL, 0\s0).
\fBsk_\f(BI\s-1TYPE\s0_reserve() allocates additional memory in the sk structure such that the next n calls to sk_\f(BI\s-1TYPE\s0_insert(), sk_\f(BI\s-1TYPE\s0_push() or sk_\f(BI\s-1TYPE\s0_unshift() will not fail or cause memory to be allocated or reallocated. If n is zero, any excess space allocated in the \fIsk structure is freed. On error sk is unchanged.
\fBsk_\f(BI\s-1TYPE\s0_new_reserve() allocates a new stack. The new stack will have additional memory allocated to hold n elements if n is positive. The next n calls to sk_\f(BI\s-1TYPE\s0_insert(), sk_\f(BI\s-1TYPE\s0_push() or \fBsk_\f(BI\s-1TYPE\s0_unshift() will not fail or cause memory to be allocated or reallocated. If n is zero or less than zero, no memory is allocated. \fBsk_\f(BI\s-1TYPE\s0_new_reserve() also sets the comparison function compare to the newly created stack. If compare is \s-1NULL\s0 then no comparison function is used.
\fBsk_\f(BI\s-1TYPE\s0_set_cmp_func() sets the comparison function of sk to \fIcompare. The previous comparison function is returned or \s-1NULL\s0 if there was no previous comparison function.
\fBsk_\f(BI\s-1TYPE\s0_free() frees up the sk structure. It does not free up any elements of sk. After this call sk is no longer valid.
\fBsk_\f(BI\s-1TYPE\s0_zero() sets the number of elements in sk to zero. It does not free sk so after this call sk is still valid.
\fBsk_\f(BI\s-1TYPE\s0_pop_free() frees up all elements of sk and sk itself. The free function freefunc() is called on each element to free it.
\fBsk_\f(BI\s-1TYPE\s0_delete() deletes element i from sk. It returns the deleted element or \s-1NULL\s0 if i is out of range.
\fBsk_\f(BI\s-1TYPE\s0_delete_ptr() deletes element matching ptr from sk. It returns the deleted element or \s-1NULL\s0 if no element matching ptr was found.
\fBsk_\f(BI\s-1TYPE\s0_insert() inserts ptr into sk at position idx. Any existing elements at or after idx are moved downwards. If idx is out of range the new element is appended to sk. sk_\f(BI\s-1TYPE\s0_insert() either returns the number of elements in sk after the new element is inserted or zero if an error (such as memory allocation failure) occurred.
\fBsk_\f(BI\s-1TYPE\s0_push() appends ptr to sk it is equivalent to:
.Vb 1 sk_TYPE_insert(sk, ptr, -1); .Ve
\fBsk_\f(BI\s-1TYPE\s0_unshift() inserts ptr at the start of sk it is equivalent to:
.Vb 1 sk_TYPE_insert(sk, ptr, 0); .Ve
\fBsk_\f(BI\s-1TYPE\s0_pop() returns and removes the last element from sk.
\fBsk_\f(BI\s-1TYPE\s0_shift() returns and removes the first element from sk.
\fBsk_\f(BI\s-1TYPE\s0_set() sets element idx of sk to ptr replacing the current element. The new element value is returned or \s-1NULL\s0 if an error occurred: this will only happen if sk is \s-1NULL\s0 or idx is out of range.
\fBsk_\f(BI\s-1TYPE\s0_find() searches sk for the element ptr. In the case where no comparison function has been specified, the function performs a linear search for a pointer equal to ptr. The index of the first matching element is returned or -1 if there is no match. In the case where a comparison function has been specified, sk is sorted and \fBsk_\f(BI\s-1TYPE\s0_find() returns the index of a matching element or -1 if there is no match. Note that, in this case the comparison function will usually compare the values pointed to rather than the pointers themselves and the order of elements in sk can change. Note that because the stack may be sorted as the result of a sk_\f(BI\s-1TYPE\s0_find() call, if a lock is being used to synchronise access to the stack across multiple threads, then that lock must be a \*(L"write\*(R" lock.
\fBsk_\f(BI\s-1TYPE\s0_find_ex() operates like sk_\f(BI\s-1TYPE\s0_find() except when a comparison function has been specified and no matching element is found. Instead of returning -1, sk_\f(BI\s-1TYPE\s0_find_ex() returns the index of the element either before or after the location where ptr would be if it were present in sk. The function also does not guarantee that the first matching element in the sorted stack is returned.
\fBsk_\f(BI\s-1TYPE\s0_find_all() operates like sk_\f(BI\s-1TYPE\s0_find() but it also sets the *pnum to number of matching elements in the stack. In case no comparison function has been specified the *pnum will be always set to 1 if matching element was found, 0 otherwise.
\fBsk_\f(BI\s-1TYPE\s0_sort() sorts sk using the supplied comparison function.
\fBsk_\f(BI\s-1TYPE\s0_is_sorted() returns 1 if sk is sorted and 0 otherwise.
\fBsk_\f(BI\s-1TYPE\s0_dup() returns a shallow copy of sk or an empty stack if the passed stack is \s-1NULL.\s0 Note the pointers in the copy are identical to the original.
\fBsk_\f(BI\s-1TYPE\s0_deep_copy() returns a new stack where each element has been copied or an empty stack if the passed stack is \s-1NULL.\s0 Copying is performed by the supplied copyfunc() and freeing by freefunc(). The function freefunc() is only called if an error occurs.
Any comparison function supplied should use a metric suitable for use in a binary search operation. That is it should return zero, a positive or negative value if a is equal to, greater than or less than b respectively.
Care should be taken when checking the return values of the functions \fBsk_\f(BI\s-1TYPE\s0_find() and sk_\f(BI\s-1TYPE\s0_find_ex(). They return an index to the matching element. In particular 0 indicates a matching first element. A failed search is indicated by a -1 return value.
\s-1STACK_OF\s0(), \s-1DEFINE_STACK_OF\s0(), \s-1DEFINE_STACK_OF_CONST\s0(), and \s-1DEFINE_SPECIAL_STACK_OF\s0() are implemented as macros.
It is not an error to call sk_\f(BI\s-1TYPE\s0_num(), sk_\f(BI\s-1TYPE\s0_value(), \fBsk_\f(BI\s-1TYPE\s0_free(), sk_\f(BI\s-1TYPE\s0_zero(), sk_\f(BI\s-1TYPE\s0_pop_free(), \fBsk_\f(BI\s-1TYPE\s0_delete(), sk_\f(BI\s-1TYPE\s0_delete_ptr(), sk_\f(BI\s-1TYPE\s0_pop(), \fBsk_\f(BI\s-1TYPE\s0_shift(), sk_\f(BI\s-1TYPE\s0_find(), sk_\f(BI\s-1TYPE\s0_find_ex(), and sk_\f(BI\s-1TYPE\s0_find_all() on a \s-1NULL\s0 stack, empty stack, or with an invalid index. An error is not raised in these conditions.
The underlying utility OPENSSL_sk_ \s-1API\s0 should not be used directly. It defines these functions: OPENSSL_sk_deep_copy(), \fBOPENSSL_sk_delete(), OPENSSL_sk_delete_ptr(), OPENSSL_sk_dup(), \fBOPENSSL_sk_find(), OPENSSL_sk_find_ex(), OPENSSL_sk_find_all(), \fBOPENSSL_sk_free(), OPENSSL_sk_insert(), OPENSSL_sk_is_sorted(), \fBOPENSSL_sk_new(), OPENSSL_sk_new_null(), OPENSSL_sk_new_reserve(), \fBOPENSSL_sk_num(), OPENSSL_sk_pop(), OPENSSL_sk_pop_free(), OPENSSL_sk_push(), \fBOPENSSL_sk_reserve(), OPENSSL_sk_set(), OPENSSL_sk_set_cmp_func(), \fBOPENSSL_sk_shift(), OPENSSL_sk_sort(), OPENSSL_sk_unshift(), \fBOPENSSL_sk_value(), OPENSSL_sk_zero().
\fBsk_\f(BI\s-1TYPE\s0_value() returns a pointer to a stack element or \s-1NULL\s0 if the index is out of range.
\fBsk_\f(BI\s-1TYPE\s0_new(), sk_\f(BI\s-1TYPE\s0_new_null() and sk_\f(BI\s-1TYPE\s0_new_reserve() return an empty stack or \s-1NULL\s0 if an error occurs.
\fBsk_\f(BI\s-1TYPE\s0_reserve() returns 1 on successful allocation of the required memory or 0 on error.
\fBsk_\f(BI\s-1TYPE\s0_set_cmp_func() returns the old comparison function or \s-1NULL\s0 if there was no old comparison function.
\fBsk_\f(BI\s-1TYPE\s0_free(), sk_\f(BI\s-1TYPE\s0_zero(), sk_\f(BI\s-1TYPE\s0_pop_free() and \fBsk_\f(BI\s-1TYPE\s0_sort() do not return values.
\fBsk_\f(BI\s-1TYPE\s0_pop(), sk_\f(BI\s-1TYPE\s0_shift(), sk_\f(BI\s-1TYPE\s0_delete() and \fBsk_\f(BI\s-1TYPE\s0_delete_ptr() return a pointer to the deleted element or \s-1NULL\s0 on error.
\fBsk_\f(BI\s-1TYPE\s0_insert(), sk_\f(BI\s-1TYPE\s0_push() and sk_\f(BI\s-1TYPE\s0_unshift() return the total number of elements in the stack and 0 if an error occurred. \fBsk_\f(BI\s-1TYPE\s0_push() further returns -1 if sk is \s-1NULL.\s0
\fBsk_\f(BI\s-1TYPE\s0_set() returns a pointer to the replacement element or \s-1NULL\s0 on error.
\fBsk_\f(BI\s-1TYPE\s0_find() and sk_\f(BI\s-1TYPE\s0_find_ex() return an index to the found element or -1 on error.
\fBsk_\f(BI\s-1TYPE\s0_is_sorted() returns 1 if the stack is sorted and 0 if it is not.
\fBsk_\f(BI\s-1TYPE\s0_dup() and sk_\f(BI\s-1TYPE\s0_deep_copy() return a pointer to the copy of the stack or \s-1NULL\s0 on error.
\fBsk_\f(BI\s-1TYPE\s0_reserve() and sk_\f(BI\s-1TYPE\s0_new_reserve() were added in OpenSSL 1.1.1.
Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use this file except in compliance with the License. You can obtain a copy in the file \s-1LICENSE\s0 in the source distribution or at <https://www.openssl.org/source/license.html>.