DEFINE_STACK_OF.3ossl 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
  2. .\"
  3. .\" Standard preamble:
  4. .\" ========================================================================
  5. .de Sp \" Vertical space (when we can't use .PP)
  6. .if t .sp .5v
  7. .if n .sp
  8. ..
  9. .de Vb \" Begin verbatim text
  10. .ft CW
  11. .nf
  12. .ne \\$1
  13. ..
  14. .de Ve \" End verbatim text
  15. .ft R
  16. .fi
  17. ..
  18. .\" Set up some character translations and predefined strings. \*(-- will
  19. .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
  20. .\" double quote, and \*(R" will give a right double quote. \*(C+ will
  21. .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
  22. .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
  23. .\" nothing in troff, for use with C<>.
  24. .tr \(*W-
  25. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  26. .ie n \{\
  27. . ds -- \(*W-
  28. . ds PI pi
  29. . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
  30. . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
  31. . ds L" ""
  32. . ds R" ""
  33. . ds C` ""
  34. . ds C' ""
  35. 'br\}
  36. .el\{\
  37. . ds -- \|\(em\|
  38. . ds PI \(*p
  39. . ds L" ``
  40. . ds R" ''
  41. . ds C`
  42. . ds C'
  43. 'br\}
  44. .\"
  45. .\" Escape single quotes in literal strings from groff's Unicode transform.
  46. .ie \n(.g .ds Aq \(aq
  47. .el .ds Aq '
  48. .\"
  49. .\" If the F register is >0, we'll generate index entries on stderr for
  50. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  51. .\" entries marked with X<> in POD. Of course, you'll have to process the
  52. .\" output yourself in some meaningful fashion.
  53. .\"
  54. .\" Avoid warning from groff about undefined register 'F'.
  55. .de IX
  56. ..
  57. .nr rF 0
  58. .if \n(.g .if rF .nr rF 1
  59. .if (\n(rF:(\n(.g==0)) \{\
  60. . if \nF \{\
  61. . de IX
  62. . tm Index:\\$1\t\\n%\t"\\$2"
  63. ..
  64. . if !\nF==2 \{\
  65. . nr % 0
  66. . nr F 2
  67. . \}
  68. . \}
  69. .\}
  70. .rr rF
  71. .\"
  72. .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
  73. .\" Fear. Run. Save yourself. No user-serviceable parts.
  74. . \" fudge factors for nroff and troff
  75. .if n \{\
  76. . ds #H 0
  77. . ds #V .8m
  78. . ds #F .3m
  79. . ds #[ \f1
  80. . ds #] \fP
  81. .\}
  82. .if t \{\
  83. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  84. . ds #V .6m
  85. . ds #F 0
  86. . ds #[ \&
  87. . ds #] \&
  88. .\}
  89. . \" simple accents for nroff and troff
  90. .if n \{\
  91. . ds ' \&
  92. . ds ` \&
  93. . ds ^ \&
  94. . ds , \&
  95. . ds ~ ~
  96. . ds /
  97. .\}
  98. .if t \{\
  99. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  100. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  101. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  102. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  103. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  104. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  105. .\}
  106. . \" troff and (daisy-wheel) nroff accents
  107. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  108. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  109. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  110. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  111. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  112. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  113. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  114. .ds ae a\h'-(\w'a'u*4/10)'e
  115. .ds Ae A\h'-(\w'A'u*4/10)'E
  116. . \" corrections for vroff
  117. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  118. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  119. . \" for low resolution devices (crt and lpr)
  120. .if \n(.H>23 .if \n(.V>19 \
  121. \{\
  122. . ds : e
  123. . ds 8 ss
  124. . ds o a
  125. . ds d- d\h'-1'\(ga
  126. . ds D- D\h'-1'\(hy
  127. . ds th \o'bp'
  128. . ds Th \o'LP'
  129. . ds ae ae
  130. . ds Ae AE
  131. .\}
  132. .rm #[ #] #H #V #F C
  133. .\" ========================================================================
  134. .\"
  135. .IX Title "DEFINE_STACK_OF 3ossl"
  136. .TH DEFINE_STACK_OF 3ossl "2024-09-03" "3.3.2" "OpenSSL"
  137. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  138. .\" way too many mistakes in technical documents.
  139. .if n .ad l
  140. .nh
  141. .SH "NAME"
  142. DEFINE_STACK_OF, DEFINE_STACK_OF_CONST, DEFINE_SPECIAL_STACK_OF,
  143. DEFINE_SPECIAL_STACK_OF_CONST,
  144. sk_TYPE_num, sk_TYPE_value, sk_TYPE_new, sk_TYPE_new_null,
  145. sk_TYPE_reserve, sk_TYPE_free, sk_TYPE_zero, sk_TYPE_delete,
  146. sk_TYPE_delete_ptr, sk_TYPE_push, sk_TYPE_unshift, sk_TYPE_pop,
  147. sk_TYPE_shift, sk_TYPE_pop_free, sk_TYPE_insert, sk_TYPE_set,
  148. sk_TYPE_find, sk_TYPE_find_ex, sk_TYPE_find_all, sk_TYPE_sort,
  149. sk_TYPE_is_sorted, sk_TYPE_dup, sk_TYPE_deep_copy, sk_TYPE_set_cmp_func,
  150. sk_TYPE_new_reserve,
  151. OPENSSL_sk_deep_copy, OPENSSL_sk_delete, OPENSSL_sk_delete_ptr,
  152. OPENSSL_sk_dup, OPENSSL_sk_find, OPENSSL_sk_find_ex, OPENSSL_sk_find_all,
  153. OPENSSL_sk_free, OPENSSL_sk_insert, OPENSSL_sk_is_sorted, OPENSSL_sk_new,
  154. OPENSSL_sk_new_null, OPENSSL_sk_new_reserve, OPENSSL_sk_num, OPENSSL_sk_pop,
  155. OPENSSL_sk_pop_free, OPENSSL_sk_push, OPENSSL_sk_reserve, OPENSSL_sk_set,
  156. OPENSSL_sk_set_cmp_func, OPENSSL_sk_shift, OPENSSL_sk_sort,
  157. OPENSSL_sk_unshift, OPENSSL_sk_value, OPENSSL_sk_zero
  158. \&\- stack container
  159. .SH "SYNOPSIS"
  160. .IX Header "SYNOPSIS"
  161. .Vb 1
  162. \& #include <openssl/safestack.h>
  163. \&
  164. \& STACK_OF(TYPE)
  165. \& DEFINE_STACK_OF(TYPE)
  166. \& DEFINE_STACK_OF_CONST(TYPE)
  167. \& DEFINE_SPECIAL_STACK_OF(FUNCTYPE, TYPE)
  168. \& DEFINE_SPECIAL_STACK_OF_CONST(FUNCTYPE, TYPE)
  169. \&
  170. \& typedef int (*sk_TYPE_compfunc)(const TYPE *const *a, const TYPE *const *b);
  171. \& typedef TYPE * (*sk_TYPE_copyfunc)(const TYPE *a);
  172. \& typedef void (*sk_TYPE_freefunc)(TYPE *a);
  173. \&
  174. \& int sk_TYPE_num(const STACK_OF(TYPE) *sk);
  175. \& TYPE *sk_TYPE_value(const STACK_OF(TYPE) *sk, int idx);
  176. \& STACK_OF(TYPE) *sk_TYPE_new(sk_TYPE_compfunc compare);
  177. \& STACK_OF(TYPE) *sk_TYPE_new_null(void);
  178. \& int sk_TYPE_reserve(STACK_OF(TYPE) *sk, int n);
  179. \& void sk_TYPE_free(STACK_OF(TYPE) *sk);
  180. \& void sk_TYPE_zero(STACK_OF(TYPE) *sk);
  181. \& TYPE *sk_TYPE_delete(STACK_OF(TYPE) *sk, int i);
  182. \& TYPE *sk_TYPE_delete_ptr(STACK_OF(TYPE) *sk, TYPE *ptr);
  183. \& int sk_TYPE_push(STACK_OF(TYPE) *sk, const TYPE *ptr);
  184. \& int sk_TYPE_unshift(STACK_OF(TYPE) *sk, const TYPE *ptr);
  185. \& TYPE *sk_TYPE_pop(STACK_OF(TYPE) *sk);
  186. \& TYPE *sk_TYPE_shift(STACK_OF(TYPE) *sk);
  187. \& void sk_TYPE_pop_free(STACK_OF(TYPE) *sk, sk_TYPE_freefunc freefunc);
  188. \& int sk_TYPE_insert(STACK_OF(TYPE) *sk, TYPE *ptr, int idx);
  189. \& TYPE *sk_TYPE_set(STACK_OF(TYPE) *sk, int idx, const TYPE *ptr);
  190. \& int sk_TYPE_find(STACK_OF(TYPE) *sk, TYPE *ptr);
  191. \& int sk_TYPE_find_ex(STACK_OF(TYPE) *sk, TYPE *ptr);
  192. \& int sk_TYPE_find_all(STACK_OF(TYPE) *sk, TYPE *ptr, int *pnum);
  193. \& void sk_TYPE_sort(const STACK_OF(TYPE) *sk);
  194. \& int sk_TYPE_is_sorted(const STACK_OF(TYPE) *sk);
  195. \& STACK_OF(TYPE) *sk_TYPE_dup(const STACK_OF(TYPE) *sk);
  196. \& STACK_OF(TYPE) *sk_TYPE_deep_copy(const STACK_OF(TYPE) *sk,
  197. \& sk_TYPE_copyfunc copyfunc,
  198. \& sk_TYPE_freefunc freefunc);
  199. \& sk_TYPE_compfunc (*sk_TYPE_set_cmp_func(STACK_OF(TYPE) *sk,
  200. \& sk_TYPE_compfunc compare));
  201. \& STACK_OF(TYPE) *sk_TYPE_new_reserve(sk_TYPE_compfunc compare, int n);
  202. .Ve
  203. .SH "DESCRIPTION"
  204. .IX Header "DESCRIPTION"
  205. Applications can create and use their own stacks by placing any of the macros
  206. described below in a header file. These macros define typesafe inline
  207. functions that wrap around the utility \fBOPENSSL_sk_\fR \s-1API.\s0
  208. In the description here, \fB\f(BI\s-1TYPE\s0\fB\fR is used
  209. as a placeholder for any of the OpenSSL datatypes, such as \fBX509\fR.
  210. .PP
  211. The \s-1\fBSTACK_OF\s0()\fR macro returns the name for a stack of the specified \fB\f(BI\s-1TYPE\s0\fB\fR.
  212. This is an opaque pointer to a structure declaration.
  213. This can be used in every header file that references the stack.
  214. There are several \fB\s-1DEFINE...\s0\fR macros that create static inline functions
  215. for all of the functions described on this page.
  216. This should normally be used in one source file, and the stack manipulation
  217. is wrapped with application-specific functions.
  218. .PP
  219. \&\s-1\fBDEFINE_STACK_OF\s0()\fR creates set of functions for a stack of \fB\f(BI\s-1TYPE\s0\fB\fR elements.
  220. The type is referenced by
  221. \&\fB\s-1STACK_OF\s0\fR(\fB\f(BI\s-1TYPE\s0\fB\fR) and each function name begins with \fBsk_\f(BI\s-1TYPE\s0\fB_\fR.
  222. \&\s-1\fBDEFINE_STACK_OF_CONST\s0()\fR is identical to \s-1\fBDEFINE_STACK_OF\s0()\fR except
  223. each element is constant.
  224. .PP
  225. .Vb 4
  226. \& /* DEFINE_STACK_OF(TYPE) */
  227. \& TYPE *sk_TYPE_value(STACK_OF(TYPE) *sk, int idx);
  228. \& /* DEFINE_STACK_OF_CONST(TYPE) */
  229. \& const TYPE *sk_TYPE_value(STACK_OF(TYPE) *sk, int idx);
  230. .Ve
  231. .PP
  232. \&\s-1\fBDEFINE_SPECIAL_STACK_OF\s0()\fR and \s-1\fBDEFINE_SPECIAL_STACK_OF_CONST\s0()\fR are similar
  233. except \fB\s-1FUNCNAME\s0\fR is used in the function names:
  234. .PP
  235. .Vb 4
  236. \& /* DEFINE_SPECIAL_STACK_OF(TYPE, FUNCNAME) */
  237. \& TYPE *sk_FUNCNAME_value(STACK_OF(TYPE) *sk, int idx);
  238. \& /* DEFINE_SPECIAL_STACK_OF(TYPE, FUNCNAME) */
  239. \& const TYPE *sk_FUNCNAME_value(STACK_OF(TYPE) *sk, int idx);
  240. .Ve
  241. .PP
  242. \&\fBsk_\f(BI\s-1TYPE\s0\fB_num\fR() returns the number of elements in \fIsk\fR or \-1 if \fIsk\fR is
  243. \&\s-1NULL.\s0
  244. .PP
  245. \&\fBsk_\f(BI\s-1TYPE\s0\fB_value\fR() returns element \fIidx\fR in \fIsk\fR, where \fIidx\fR starts at
  246. zero. If \fIidx\fR is out of range then \s-1NULL\s0 is returned.
  247. .PP
  248. \&\fBsk_\f(BI\s-1TYPE\s0\fB_new\fR() allocates a new empty stack using comparison function
  249. \&\fIcompare\fR. If \fIcompare\fR is \s-1NULL\s0 then no comparison function is used. This
  250. function is equivalent to \fBsk_\f(BI\s-1TYPE\s0\fB_new_reserve\fR(\fIcompare\fR, 0).
  251. .PP
  252. \&\fBsk_\f(BI\s-1TYPE\s0\fB_new_null\fR() allocates a new empty stack with no comparison
  253. function. This function is equivalent to \fBsk_\f(BI\s-1TYPE\s0\fB_new_reserve\fR(\s-1NULL, 0\s0).
  254. .PP
  255. \&\fBsk_\f(BI\s-1TYPE\s0\fB_reserve\fR() allocates additional memory in the \fIsk\fR structure
  256. such that the next \fIn\fR calls to \fBsk_\f(BI\s-1TYPE\s0\fB_insert\fR(), \fBsk_\f(BI\s-1TYPE\s0\fB_push\fR()
  257. or \fBsk_\f(BI\s-1TYPE\s0\fB_unshift\fR() will not fail or cause memory to be allocated
  258. or reallocated. If \fIn\fR is zero, any excess space allocated in the
  259. \&\fIsk\fR structure is freed. On error \fIsk\fR is unchanged.
  260. .PP
  261. \&\fBsk_\f(BI\s-1TYPE\s0\fB_new_reserve\fR() allocates a new stack. The new stack will have
  262. additional memory allocated to hold \fIn\fR elements if \fIn\fR is positive.
  263. The next \fIn\fR calls to \fBsk_\f(BI\s-1TYPE\s0\fB_insert\fR(), \fBsk_\f(BI\s-1TYPE\s0\fB_push\fR() or
  264. \&\fBsk_\f(BI\s-1TYPE\s0\fB_unshift\fR() will not fail or cause memory to be allocated or
  265. reallocated. If \fIn\fR is zero or less than zero, no memory is allocated.
  266. \&\fBsk_\f(BI\s-1TYPE\s0\fB_new_reserve\fR() also sets the comparison function \fIcompare\fR
  267. to the newly created stack. If \fIcompare\fR is \s-1NULL\s0 then no comparison
  268. function is used.
  269. .PP
  270. \&\fBsk_\f(BI\s-1TYPE\s0\fB_set_cmp_func\fR() sets the comparison function of \fIsk\fR to
  271. \&\fIcompare\fR. The previous comparison function is returned or \s-1NULL\s0 if there
  272. was no previous comparison function.
  273. .PP
  274. \&\fBsk_\f(BI\s-1TYPE\s0\fB_free\fR() frees up the \fIsk\fR structure. It does \fInot\fR free up any
  275. elements of \fIsk\fR. After this call \fIsk\fR is no longer valid.
  276. .PP
  277. \&\fBsk_\f(BI\s-1TYPE\s0\fB_zero\fR() sets the number of elements in \fIsk\fR to zero. It does not
  278. free \fIsk\fR so after this call \fIsk\fR is still valid.
  279. .PP
  280. \&\fBsk_\f(BI\s-1TYPE\s0\fB_pop_free\fR() frees up all elements of \fIsk\fR and \fIsk\fR itself. The
  281. free function \fBfreefunc()\fR is called on each element to free it.
  282. .PP
  283. \&\fBsk_\f(BI\s-1TYPE\s0\fB_delete\fR() deletes element \fIi\fR from \fIsk\fR. It returns the deleted
  284. element or \s-1NULL\s0 if \fIi\fR is out of range.
  285. .PP
  286. \&\fBsk_\f(BI\s-1TYPE\s0\fB_delete_ptr\fR() deletes element matching \fIptr\fR from \fIsk\fR. It
  287. returns the deleted element or \s-1NULL\s0 if no element matching \fIptr\fR was found.
  288. .PP
  289. \&\fBsk_\f(BI\s-1TYPE\s0\fB_insert\fR() inserts \fIptr\fR into \fIsk\fR at position \fIidx\fR. Any
  290. existing elements at or after \fIidx\fR are moved downwards. If \fIidx\fR is out
  291. of range the new element is appended to \fIsk\fR. \fBsk_\f(BI\s-1TYPE\s0\fB_insert\fR() either
  292. returns the number of elements in \fIsk\fR after the new element is inserted or
  293. zero if an error (such as memory allocation failure) occurred.
  294. .PP
  295. \&\fBsk_\f(BI\s-1TYPE\s0\fB_push\fR() appends \fIptr\fR to \fIsk\fR it is equivalent to:
  296. .PP
  297. .Vb 1
  298. \& sk_TYPE_insert(sk, ptr, \-1);
  299. .Ve
  300. .PP
  301. \&\fBsk_\f(BI\s-1TYPE\s0\fB_unshift\fR() inserts \fIptr\fR at the start of \fIsk\fR it is equivalent
  302. to:
  303. .PP
  304. .Vb 1
  305. \& sk_TYPE_insert(sk, ptr, 0);
  306. .Ve
  307. .PP
  308. \&\fBsk_\f(BI\s-1TYPE\s0\fB_pop\fR() returns and removes the last element from \fIsk\fR.
  309. .PP
  310. \&\fBsk_\f(BI\s-1TYPE\s0\fB_shift\fR() returns and removes the first element from \fIsk\fR.
  311. .PP
  312. \&\fBsk_\f(BI\s-1TYPE\s0\fB_set\fR() sets element \fIidx\fR of \fIsk\fR to \fIptr\fR replacing the current
  313. element. The new element value is returned or \s-1NULL\s0 if an error occurred:
  314. this will only happen if \fIsk\fR is \s-1NULL\s0 or \fIidx\fR is out of range.
  315. .PP
  316. \&\fBsk_\f(BI\s-1TYPE\s0\fB_find\fR() searches \fIsk\fR for the element \fIptr\fR. In the case
  317. where no comparison function has been specified, the function performs
  318. a linear search for a pointer equal to \fIptr\fR. The index of the first
  319. matching element is returned or \fB\-1\fR if there is no match. In the case
  320. where a comparison function has been specified, \fIsk\fR is sorted and
  321. \&\fBsk_\f(BI\s-1TYPE\s0\fB_find\fR() returns the index of a matching element or \fB\-1\fR if there
  322. is no match. Note that, in this case the comparison function will usually
  323. compare the values pointed to rather than the pointers themselves and
  324. the order of elements in \fIsk\fR can change.
  325. .PP
  326. \&\fBsk_\f(BI\s-1TYPE\s0\fB_find_ex\fR() operates like \fBsk_\f(BI\s-1TYPE\s0\fB_find\fR() except when a
  327. comparison function has been specified and no matching element is found.
  328. Instead of returning \fB\-1\fR, \fBsk_\f(BI\s-1TYPE\s0\fB_find_ex\fR() returns the index of the
  329. element either before or after the location where \fIptr\fR would be if it were
  330. present in \fIsk\fR. The function also does not guarantee that the first matching
  331. element in the sorted stack is returned.
  332. .PP
  333. \&\fBsk_\f(BI\s-1TYPE\s0\fB_find_all\fR() operates like \fBsk_\f(BI\s-1TYPE\s0\fB_find\fR() but it also
  334. sets the \fI*pnum\fR to number of matching elements in the stack. In case
  335. no comparison function has been specified the \fI*pnum\fR will be always set
  336. to 1 if matching element was found, 0 otherwise.
  337. .PP
  338. \&\fBsk_\f(BI\s-1TYPE\s0\fB_sort\fR() sorts \fIsk\fR using the supplied comparison function.
  339. .PP
  340. \&\fBsk_\f(BI\s-1TYPE\s0\fB_is_sorted\fR() returns \fB1\fR if \fIsk\fR is sorted and \fB0\fR otherwise.
  341. .PP
  342. \&\fBsk_\f(BI\s-1TYPE\s0\fB_dup\fR() returns a shallow copy of \fIsk\fR
  343. or an empty stack if the passed stack is \s-1NULL.\s0
  344. Note the pointers in the copy are identical to the original.
  345. .PP
  346. \&\fBsk_\f(BI\s-1TYPE\s0\fB_deep_copy\fR() returns a new stack where each element has been
  347. copied or an empty stack if the passed stack is \s-1NULL.\s0
  348. Copying is performed by the supplied \fBcopyfunc()\fR and freeing by \fBfreefunc()\fR.
  349. The function \fBfreefunc()\fR is only called if an error occurs.
  350. .SH "NOTES"
  351. .IX Header "NOTES"
  352. Care should be taken when accessing stacks in multi-threaded environments.
  353. Any operation which increases the size of a stack such as \fBsk_\f(BI\s-1TYPE\s0\fB_insert\fR()
  354. or \fBsk_\f(BI\s-1TYPE\s0\fB_push\fR() can \*(L"grow\*(R" the size of an internal array and cause race
  355. conditions if the same stack is accessed in a different thread. Operations such
  356. as \fBsk_\f(BI\s-1TYPE\s0\fB_find\fR() and \fBsk_\f(BI\s-1TYPE\s0\fB_sort\fR() can also reorder the stack.
  357. .PP
  358. Any comparison function supplied should use a metric suitable
  359. for use in a binary search operation. That is it should return zero, a
  360. positive or negative value if \fIa\fR is equal to, greater than
  361. or less than \fIb\fR respectively.
  362. .PP
  363. Care should be taken when checking the return values of the functions
  364. \&\fBsk_\f(BI\s-1TYPE\s0\fB_find\fR() and \fBsk_\f(BI\s-1TYPE\s0\fB_find_ex\fR(). They return an index to the
  365. matching element. In particular \fB0\fR indicates a matching first element.
  366. A failed search is indicated by a \fB\-1\fR return value.
  367. .PP
  368. \&\s-1\fBSTACK_OF\s0()\fR, \s-1\fBDEFINE_STACK_OF\s0()\fR, \s-1\fBDEFINE_STACK_OF_CONST\s0()\fR, and
  369. \&\s-1\fBDEFINE_SPECIAL_STACK_OF\s0()\fR are implemented as macros.
  370. .PP
  371. It is not an error to call \fBsk_\f(BI\s-1TYPE\s0\fB_num\fR(), \fBsk_\f(BI\s-1TYPE\s0\fB_value\fR(),
  372. \&\fBsk_\f(BI\s-1TYPE\s0\fB_free\fR(), \fBsk_\f(BI\s-1TYPE\s0\fB_zero\fR(), \fBsk_\f(BI\s-1TYPE\s0\fB_pop_free\fR(),
  373. \&\fBsk_\f(BI\s-1TYPE\s0\fB_delete\fR(), \fBsk_\f(BI\s-1TYPE\s0\fB_delete_ptr\fR(), \fBsk_\f(BI\s-1TYPE\s0\fB_pop\fR(),
  374. \&\fBsk_\f(BI\s-1TYPE\s0\fB_shift\fR(), \fBsk_\f(BI\s-1TYPE\s0\fB_find\fR(), \fBsk_\f(BI\s-1TYPE\s0\fB_find_ex\fR(),
  375. and \fBsk_\f(BI\s-1TYPE\s0\fB_find_all\fR() on a \s-1NULL\s0 stack, empty stack, or with
  376. an invalid index. An error is not raised in these conditions.
  377. .PP
  378. The underlying utility \fBOPENSSL_sk_\fR \s-1API\s0 should not be used directly.
  379. It defines these functions: \fBOPENSSL_sk_deep_copy()\fR,
  380. \&\fBOPENSSL_sk_delete()\fR, \fBOPENSSL_sk_delete_ptr()\fR, \fBOPENSSL_sk_dup()\fR,
  381. \&\fBOPENSSL_sk_find()\fR, \fBOPENSSL_sk_find_ex()\fR, \fBOPENSSL_sk_find_all()\fR,
  382. \&\fBOPENSSL_sk_free()\fR, \fBOPENSSL_sk_insert()\fR, \fBOPENSSL_sk_is_sorted()\fR,
  383. \&\fBOPENSSL_sk_new()\fR, \fBOPENSSL_sk_new_null()\fR, \fBOPENSSL_sk_new_reserve()\fR,
  384. \&\fBOPENSSL_sk_num()\fR, \fBOPENSSL_sk_pop()\fR, \fBOPENSSL_sk_pop_free()\fR, \fBOPENSSL_sk_push()\fR,
  385. \&\fBOPENSSL_sk_reserve()\fR, \fBOPENSSL_sk_set()\fR, \fBOPENSSL_sk_set_cmp_func()\fR,
  386. \&\fBOPENSSL_sk_shift()\fR, \fBOPENSSL_sk_sort()\fR, \fBOPENSSL_sk_unshift()\fR,
  387. \&\fBOPENSSL_sk_value()\fR, \fBOPENSSL_sk_zero()\fR.
  388. .SH "RETURN VALUES"
  389. .IX Header "RETURN VALUES"
  390. \&\fBsk_\f(BI\s-1TYPE\s0\fB_num\fR() returns the number of elements in the stack or \fB\-1\fR if the
  391. passed stack is \s-1NULL.\s0
  392. .PP
  393. \&\fBsk_\f(BI\s-1TYPE\s0\fB_value\fR() returns a pointer to a stack element or \s-1NULL\s0 if the
  394. index is out of range.
  395. .PP
  396. \&\fBsk_\f(BI\s-1TYPE\s0\fB_new\fR(), \fBsk_\f(BI\s-1TYPE\s0\fB_new_null\fR() and \fBsk_\f(BI\s-1TYPE\s0\fB_new_reserve\fR()
  397. return an empty stack or \s-1NULL\s0 if an error occurs.
  398. .PP
  399. \&\fBsk_\f(BI\s-1TYPE\s0\fB_reserve\fR() returns \fB1\fR on successful allocation of the required
  400. memory or \fB0\fR on error.
  401. .PP
  402. \&\fBsk_\f(BI\s-1TYPE\s0\fB_set_cmp_func\fR() returns the old comparison function or \s-1NULL\s0 if
  403. there was no old comparison function.
  404. .PP
  405. \&\fBsk_\f(BI\s-1TYPE\s0\fB_free\fR(), \fBsk_\f(BI\s-1TYPE\s0\fB_zero\fR(), \fBsk_\f(BI\s-1TYPE\s0\fB_pop_free\fR() and
  406. \&\fBsk_\f(BI\s-1TYPE\s0\fB_sort\fR() do not return values.
  407. .PP
  408. \&\fBsk_\f(BI\s-1TYPE\s0\fB_pop\fR(), \fBsk_\f(BI\s-1TYPE\s0\fB_shift\fR(), \fBsk_\f(BI\s-1TYPE\s0\fB_delete\fR() and
  409. \&\fBsk_\f(BI\s-1TYPE\s0\fB_delete_ptr\fR() return a pointer to the deleted element or \s-1NULL\s0
  410. on error.
  411. .PP
  412. \&\fBsk_\f(BI\s-1TYPE\s0\fB_insert\fR(), \fBsk_\f(BI\s-1TYPE\s0\fB_push\fR() and \fBsk_\f(BI\s-1TYPE\s0\fB_unshift\fR() return
  413. the total number of elements in the stack and 0 if an error occurred.
  414. .PP
  415. \&\fBsk_\f(BI\s-1TYPE\s0\fB_set\fR() returns a pointer to the replacement element or \s-1NULL\s0 on
  416. error.
  417. .PP
  418. \&\fBsk_\f(BI\s-1TYPE\s0\fB_find\fR() and \fBsk_\f(BI\s-1TYPE\s0\fB_find_ex\fR() return an index to the found
  419. element or \fB\-1\fR on error.
  420. .PP
  421. \&\fBsk_\f(BI\s-1TYPE\s0\fB_is_sorted\fR() returns \fB1\fR if the stack is sorted and \fB0\fR if it is
  422. not.
  423. .PP
  424. \&\fBsk_\f(BI\s-1TYPE\s0\fB_dup\fR() and \fBsk_\f(BI\s-1TYPE\s0\fB_deep_copy\fR() return a pointer to the copy
  425. of the stack or \s-1NULL\s0 on error.
  426. .SH "HISTORY"
  427. .IX Header "HISTORY"
  428. Before OpenSSL 1.1.0, this was implemented via macros and not inline functions
  429. and was not a public \s-1API.\s0
  430. .PP
  431. \&\fBsk_\f(BI\s-1TYPE\s0\fB_reserve\fR() and \fBsk_\f(BI\s-1TYPE\s0\fB_new_reserve\fR() were added in OpenSSL
  432. 1.1.1.
  433. .PP
  434. From OpenSSL 3.2.0, the \fBsk_\f(BI\s-1TYPE\s0\fB_find\fR(), \fBsk_\f(BI\s-1TYPE\s0\fB_find_ex\fR()
  435. and \fBsk_\f(BI\s-1TYPE\s0\fB_find_all\fR() calls are read-only and do not sort the
  436. stack. To avoid any performance implications this change introduces,
  437. \&\fBsk_\f(BI\s-1TYPE\s0\fB_sort\fR() should be called before these find operations.
  438. .PP
  439. Before OpenSSL 3.3.0 \fBsk_\f(BI\s-1TYPE\s0\fB_push\fR() returned \-1 if \fIsk\fR was \s-1NULL.\s0 It
  440. was changed to return 0 in this condition as for other errors.
  441. .SH "COPYRIGHT"
  442. .IX Header "COPYRIGHT"
  443. Copyright 2000\-2024 The OpenSSL Project Authors. All Rights Reserved.
  444. .PP
  445. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  446. this file except in compliance with the License. You can obtain a copy
  447. in the file \s-1LICENSE\s0 in the source distribution or at
  448. <https://www.openssl.org/source/license.html>.