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 Remove an element from a linked list.
29 * This function removes a specified element from a linked list.
31 * \param list A pointer to a #link_head_t.
32 * \param elem A pointer to the #link_elem_t describing the element
35 * \retval DB_ERR_BADARGS An argument was invalid.
36 * \retval DB_ERR_UNUSED \p elem is not in a linked list.
37 * \retval DB_ERR_WRONGTABLE \p elem is not in this linked list.
40 ll_remove(link_head_t *list, link_elem_t *elem)
42 initialize_dbpr_error_table(); /* initialize error table */
44 if (!ll_verify(list) || !le_verify(elem)) /* First, verify the arguments */
45 return DB_ERR_BADARGS;
47 if (!elem->le_head) /* is the element even being used? */
49 if (list != elem->le_head) /* Verify that the element is in this list */
50 return DB_ERR_WRONGTABLE;
52 list->lh_count--; /* OK, reduce the list count */
54 if (elem->le_next) /* Clip the list back together */
55 elem->le_next->le_prev = elem->le_prev;
57 elem->le_prev->le_next = elem->le_next;
59 list->lh_first = elem->le_next;
61 if (list->lh_last == elem) /* Make sure we know where the last element is */
62 list->lh_last = elem->le_prev;
64 elem->le_next = 0; /* Clear the element out */