2 ** Copyright (C) 2002 by Kevin L. Mitchell <klmitch@mit.edu>
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Library General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2 of the License, or (at your option) any later version.
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Library General Public License for more details.
14 ** You should have received a copy of the GNU Library General Public
15 ** License along with this library; if not, write to the Free
16 ** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 #include "dbprim_int.h"
26 /** \ingroup dbprim_link
27 * \brief Flush a linked list.
29 * This function flushes a linked list--that is, it removes each
30 * element from the list. If a \p flush_func is specified, it will be
31 * called on the entry after it has been removed from the list, and
32 * may safely call <CODE>free()</CODE>.
34 * \param list A pointer to a #link_head_t.
36 * A pointer to a callback function used to perform
37 * user-specified actions on an element after removing it
38 * from the list. May be \c NULL. See the documentation
39 * for #link_iter_t for more information.
40 * \param extra A \c void pointer that will be passed to \p
43 * \retval DB_ERR_BADARGS An argument was invalid.
46 ll_flush(link_head_t *list, link_iter_t flush_func, void *extra)
51 initialize_dbpr_error_table(); /* initialize error table */
53 if (!ll_verify(list)) /* Verify arguments */
54 return DB_ERR_BADARGS;
56 while ((elem = list->lh_first)) { /* Walk through the list... */
57 ll_remove(list, elem); /* remove the element */
58 /* call flush function, erroring out if it fails */
59 if (flush_func && (retval = (*flush_func)(list, elem, extra)))
63 list->lh_count = 0; /* clear the list head */