1*592efe25SPierre Pronchery /*
2*592efe25SPierre Pronchery * bufferset.c
3*592efe25SPierre Pronchery * dynamically-managed buffer sets
4*592efe25SPierre Pronchery *
5*592efe25SPierre Pronchery * SPDX-License-Identifier: pkgconf
6*592efe25SPierre Pronchery *
7*592efe25SPierre Pronchery * Copyright (c) 2026 pkgconf authors (see AUTHORS).
8*592efe25SPierre Pronchery *
9*592efe25SPierre Pronchery * Permission to use, copy, modify, and/or distribute this software for any
10*592efe25SPierre Pronchery * purpose with or without fee is hereby granted, provided that the above
11*592efe25SPierre Pronchery * copyright notice and this permission notice appear in all copies.
12*592efe25SPierre Pronchery *
13*592efe25SPierre Pronchery * This software is provided 'as is' and without any warranty, express or
14*592efe25SPierre Pronchery * implied. In no event shall the authors be liable for any damages arising
15*592efe25SPierre Pronchery * from the use of this software.
16*592efe25SPierre Pronchery */
17*592efe25SPierre Pronchery
18*592efe25SPierre Pronchery #include <libpkgconf/stdinc.h>
19*592efe25SPierre Pronchery #include <libpkgconf/libpkgconf.h>
20*592efe25SPierre Pronchery
21*592efe25SPierre Pronchery /*
22*592efe25SPierre Pronchery * !doc
23*592efe25SPierre Pronchery *
24*592efe25SPierre Pronchery * libpkgconf `bufferset` module
25*592efe25SPierre Pronchery * =============================
26*592efe25SPierre Pronchery *
27*592efe25SPierre Pronchery * The libpkgconf `bufferset` module contains the functions related to managing
28*592efe25SPierre Pronchery * dynamically-allocated sets of buffers.
29*592efe25SPierre Pronchery */
30*592efe25SPierre Pronchery
31*592efe25SPierre Pronchery pkgconf_bufferset_t *
pkgconf_bufferset_extend(pkgconf_list_t * list,pkgconf_buffer_t * buffer)32*592efe25SPierre Pronchery pkgconf_bufferset_extend(pkgconf_list_t *list, pkgconf_buffer_t *buffer)
33*592efe25SPierre Pronchery {
34*592efe25SPierre Pronchery pkgconf_bufferset_t *set = calloc(1, sizeof(*set));
35*592efe25SPierre Pronchery if (set == NULL)
36*592efe25SPierre Pronchery return NULL;
37*592efe25SPierre Pronchery
38*592efe25SPierre Pronchery if (pkgconf_buffer_len(buffer))
39*592efe25SPierre Pronchery {
40*592efe25SPierre Pronchery if (!pkgconf_buffer_append(&set->buffer, pkgconf_buffer_str(buffer)))
41*592efe25SPierre Pronchery {
42*592efe25SPierre Pronchery free(set);
43*592efe25SPierre Pronchery return NULL;
44*592efe25SPierre Pronchery }
45*592efe25SPierre Pronchery }
46*592efe25SPierre Pronchery
47*592efe25SPierre Pronchery pkgconf_node_insert_tail(&set->node, set, list);
48*592efe25SPierre Pronchery return set;
49*592efe25SPierre Pronchery }
50*592efe25SPierre Pronchery
51*592efe25SPierre Pronchery void
pkgconf_bufferset_free(pkgconf_list_t * list)52*592efe25SPierre Pronchery pkgconf_bufferset_free(pkgconf_list_t *list)
53*592efe25SPierre Pronchery {
54*592efe25SPierre Pronchery pkgconf_node_t *iter, *iter_next;
55*592efe25SPierre Pronchery
56*592efe25SPierre Pronchery PKGCONF_FOREACH_LIST_ENTRY_SAFE(list->head, iter_next, iter)
57*592efe25SPierre Pronchery {
58*592efe25SPierre Pronchery pkgconf_bufferset_t *set = iter->data;
59*592efe25SPierre Pronchery
60*592efe25SPierre Pronchery pkgconf_buffer_finalize(&set->buffer);
61*592efe25SPierre Pronchery pkgconf_node_delete(&set->node, list);
62*592efe25SPierre Pronchery
63*592efe25SPierre Pronchery free(set);
64*592efe25SPierre Pronchery }
65*592efe25SPierre Pronchery }
66