/[svn]/hopm/trunk/src/list.c
ViewVC logotype

Contents of /hopm/trunk/src/list.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5135 - (show annotations)
Thu Dec 25 18:51:51 2014 UTC (5 years, 5 months ago) by michael
File MIME type: text/x-chdr
File size: 2185 byte(s)
- propset svn:eol-style native

1 /*
2 * Copyright (C) 2002-2003 Erik Fears
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program 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
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to
16 *
17 * The Free Software Foundation, Inc.
18 * 59 Temple Place - Suite 330
19 * Boston, MA 02111-1307, USA.
20 *
21 *
22 */
23
24 #include "malloc.h"
25 #include "list.h"
26
27
28 node_t *node_create(void *data)
29 {
30 node_t *node = MyMalloc(sizeof *node);
31 node->next = NULL;
32 node->prev = NULL;
33 node->data = (void *) data;
34
35 return node;
36 }
37
38 list_t *list_create()
39 {
40 list_t *list = MyMalloc(sizeof *list);
41
42 list->head = NULL;
43 list->tail = NULL;
44
45 list->elements = 0;
46
47 return list;
48 }
49
50 node_t *list_add(list_t *list, node_t *node)
51 {
52
53 if(list == NULL || node == NULL)
54 return NULL;
55
56 if(list->tail == NULL)
57 {
58 list->head = node;
59 list->tail = node;
60
61 node->next = NULL;
62 node->prev = NULL;
63 }
64 else
65 {
66 node->prev = list->tail;
67 list->tail->next = node;
68 list->tail = node;
69 node->next = NULL;
70 }
71
72 list->elements++;
73 return node;
74 }
75
76 node_t *list_remove(list_t *list, node_t *node)
77 {
78 if(list == NULL || node == NULL)
79 return NULL;
80
81 if(node == list->head)
82 {
83 list->head = node->next;
84
85 if(node->next)
86 node->next->prev = NULL;
87 else
88 list->tail = NULL;
89 }
90 else if(node == list->tail)
91 {
92 list->tail = list->tail->prev;
93 list->tail->next = NULL;
94 }
95 else
96 {
97 node->prev->next = node->next;
98 node->next->prev = node->prev;
99 }
100
101 list->elements--;
102 return node;
103 }
104
105 void list_free(list_t *list)
106 {
107 MyFree(list);
108 }
109
110 void node_free(node_t *node)
111 {
112 MyFree(node);
113 }

Properties

Name Value
svn:eol-style native
svn:keywords Id

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28