1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
Code for handling dubble-linked lists in C
20
#include "mysys_priv.h"
27
/* Add a element to start of list */
29
LIST *list_add(LIST *root, LIST *element)
33
if (root->prev) /* If add in mid of list */
34
root->prev->next= element;
35
element->prev=root->prev;
41
return(element); /* New root */
45
LIST *list_delete(LIST *root, LIST *element)
48
element->prev->next=element->next;
52
element->next->prev=element->prev;
57
void list_free(LIST *root, uint32_t free_data)
64
free((unsigned char*) root->data);
65
free((unsigned char*) root);
71
LIST *list_cons(void *data, LIST *list)
73
LIST * const new_charset=(LIST*) malloc(sizeof(LIST));
76
new_charset->data=data;
77
return list_add(list,new_charset);
81
LIST *list_reverse(LIST *root)
90
last->next=last->prev;
96
int list_walk(LIST *list, list_walk_action action, unsigned char* argument)
101
if ((error = (*action)(list->data,argument)))
103
list=list_rest(list);