00001 /* src/kernel/list.c 00002 CubeOS Version 0.4.90 00003 Copyright (C) 1999,2000 Holger Kenn 00004 00005 CubeOS is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or any later version. 00009 00010 CubeOS is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 */ 00016 #include <stddef.h> 00017 #include <list.h> 00027 entry * 00028 LIST_head (list * l) 00029 { 00030 if (l == NULL) 00031 return NULL; 00032 return l->head; 00033 } 00034 00040 entry * 00041 LIST_tail (list * l) 00042 { 00043 if (l == NULL) 00044 return NULL; 00045 return l->tail; 00046 } 00047 00053 void LIST_init (list * l) 00054 { 00055 if (l == NULL) 00056 return; 00057 l->head = NULL; 00058 l->tail = NULL; 00059 l->entries = 0; 00060 l->type = LIST_TYPE_USER; 00061 } 00062 00068 int LIST_entries (list * l) 00069 { 00070 if (l == NULL) 00071 return -1; 00072 return l->entries; 00073 } 00074 00084 void LIST_insert_after (entry * e, entry * x) 00085 { 00086 if (e == NULL) 00087 return; 00088 if (e->list) 00089 return; 00090 if (x == NULL) 00091 return; 00092 if (x->list == NULL) 00093 return; 00094 e->prev = x; 00095 e->next = x->next; 00096 x->next = e; 00097 if (x->list->tail == x) 00098 x->list->tail = e; 00099 e->list = x->list; 00100 e->list->entries++; 00101 } 00102 00103 00113 void LIST_insert_before (entry * e, entry * x) 00114 { 00115 if (e == NULL) 00116 return; 00117 if (e->list) 00118 return; 00119 if (x == NULL) 00120 return; 00121 if (x->list == NULL) 00122 return; 00123 e->prev = x->prev; 00124 e->next = x; 00125 x->prev = e; 00126 if (x->list->head == x) 00127 x->list->head = e; 00128 e->list = x->list; 00129 e->list->entries++; 00130 } 00131 00132 00141 void LIST_insert_head (list * l, entry * e) 00142 { 00143 if (l == NULL) 00144 return; 00145 if (e == NULL) 00146 return; 00147 if (e->list) 00148 return; 00149 if (l->head == NULL) { 00150 l->head = e; 00151 l->tail = e; 00152 e->prev = NULL; 00153 e->next = NULL; 00154 e->list = l; 00155 l->entries++; 00156 } else 00157 LIST_insert_before (e, l->head); 00158 } 00159 00168 void LIST_insert_tail (list * l, entry * e) 00169 { 00170 if (l == NULL) 00171 return; 00172 if (e == NULL) 00173 return; 00174 if (e->list) 00175 return; 00176 if (l->tail == NULL) { 00177 l->head = e; 00178 l->tail = e; 00179 e->prev = NULL; 00180 e->next = NULL; 00181 e->list = l; 00182 l->entries++; 00183 } else 00184 LIST_insert_after (e, l->tail); 00185 } 00186 00195 void LIST_delete (entry * e) 00196 { 00197 if (e == NULL) 00198 return; 00199 if (e->list == NULL) 00200 return; 00201 if (e->prev) 00202 e->prev->next = e->next; 00203 if (e->next) 00204 e->next->prev = e->prev; 00205 if (e == e->list->tail) 00206 e->list->tail = e->prev; 00207 if (e == e->list->head) 00208 e->list->head = e->next; 00209 e->list->entries--; 00210 e->list = NULL; 00211 } 00212 00218 void LIST_makeentry (entry * e) 00219 { 00220 if (e == NULL) 00221 return; 00222 e->list = NULL; 00223 e->prev = NULL; 00224 e->next = NULL; 00225 e->data = NULL; 00226 e->len = 0; 00227 }