diff options
Diffstat (limited to 'src/lib/libcrypto/objects/o_names.c')
-rw-r--r-- | src/lib/libcrypto/objects/o_names.c | 81 |
1 files changed, 1 insertions, 80 deletions
diff --git a/src/lib/libcrypto/objects/o_names.c b/src/lib/libcrypto/objects/o_names.c index 48b95d6767..1007c5e23a 100644 --- a/src/lib/libcrypto/objects/o_names.c +++ b/src/lib/libcrypto/objects/o_names.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: o_names.c,v 1.24 2023/07/08 12:27:51 beck Exp $ */ | 1 | /* $OpenBSD: o_names.c,v 1.25 2024/01/13 11:08:39 tb Exp $ */ |
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <string.h> | 4 | #include <string.h> |
@@ -240,85 +240,6 @@ OBJ_NAME_remove(const char *name, int type) | |||
240 | } | 240 | } |
241 | LCRYPTO_ALIAS(OBJ_NAME_remove); | 241 | LCRYPTO_ALIAS(OBJ_NAME_remove); |
242 | 242 | ||
243 | struct doall { | ||
244 | int type; | ||
245 | void (*fn)(const OBJ_NAME *, void *arg); | ||
246 | void *arg; | ||
247 | }; | ||
248 | |||
249 | static void | ||
250 | do_all_fn_doall_arg(const OBJ_NAME *name, struct doall *d) | ||
251 | { | ||
252 | if (name->type == d->type) | ||
253 | d->fn(name, d->arg); | ||
254 | } | ||
255 | |||
256 | static IMPLEMENT_LHASH_DOALL_ARG_FN(do_all_fn, const OBJ_NAME, struct doall) | ||
257 | |||
258 | void | ||
259 | OBJ_NAME_do_all(int type, void (*fn)(const OBJ_NAME *, void *arg), void *arg) | ||
260 | { | ||
261 | struct doall d; | ||
262 | |||
263 | d.type = type; | ||
264 | d.fn = fn; | ||
265 | d.arg = arg; | ||
266 | |||
267 | lh_OBJ_NAME_doall_arg(names_lh, LHASH_DOALL_ARG_FN(do_all_fn), | ||
268 | struct doall, &d); | ||
269 | } | ||
270 | LCRYPTO_ALIAS(OBJ_NAME_do_all); | ||
271 | |||
272 | struct doall_sorted { | ||
273 | int type; | ||
274 | int n; | ||
275 | const OBJ_NAME **names; | ||
276 | }; | ||
277 | |||
278 | static void | ||
279 | do_all_sorted_fn(const OBJ_NAME *name, void *d_) | ||
280 | { | ||
281 | struct doall_sorted *d = d_; | ||
282 | |||
283 | if (name->type != d->type) | ||
284 | return; | ||
285 | |||
286 | d->names[d->n++] = name; | ||
287 | } | ||
288 | |||
289 | static int | ||
290 | do_all_sorted_cmp(const void *n1_, const void *n2_) | ||
291 | { | ||
292 | const OBJ_NAME * const *n1 = n1_; | ||
293 | const OBJ_NAME * const *n2 = n2_; | ||
294 | |||
295 | return strcmp((*n1)->name, (*n2)->name); | ||
296 | } | ||
297 | |||
298 | void | ||
299 | OBJ_NAME_do_all_sorted(int type, void (*fn)(const OBJ_NAME *, void *arg), | ||
300 | void *arg) | ||
301 | { | ||
302 | struct doall_sorted d; | ||
303 | int n; | ||
304 | |||
305 | d.type = type; | ||
306 | d.names = reallocarray(NULL, lh_OBJ_NAME_num_items(names_lh), | ||
307 | sizeof *d.names); | ||
308 | d.n = 0; | ||
309 | if (d.names != NULL) { | ||
310 | OBJ_NAME_do_all(type, do_all_sorted_fn, &d); | ||
311 | |||
312 | qsort((void *)d.names, d.n, sizeof *d.names, do_all_sorted_cmp); | ||
313 | |||
314 | for (n = 0; n < d.n; ++n) | ||
315 | fn(d.names[n], arg); | ||
316 | |||
317 | free(d.names); | ||
318 | } | ||
319 | } | ||
320 | LCRYPTO_ALIAS(OBJ_NAME_do_all_sorted); | ||
321 | |||
322 | static int free_type; | 243 | static int free_type; |
323 | 244 | ||
324 | static void | 245 | static void |