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