Clean up int21 handling. Move error handling to winedos.
[wine/multimedia.git] / server / list.h
blobfcf687e3e663e9aef49bfe66c424b12a4d19d55f
1 /*
2 * Linked lists support
4 * Copyright (C) 2002 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef __WINE_SERVER_LIST_H
22 #define __WINE_SERVER_LIST_H
24 struct list
26 struct list *next;
27 struct list *prev;
30 /* add element at the head of the list */
31 inline static void list_add_head( struct list *list, struct list *elem )
33 elem->next = list->next;
34 elem->prev = list;
35 list->next->prev = elem;
36 list->next = elem;
39 /* add element at the tail of the list */
40 inline static void list_add_tail( struct list *list, struct list *elem )
42 elem->next = list;
43 elem->prev = list->prev;
44 list->prev->next = elem;
45 list->prev = elem;
48 /* remove an element from its list */
49 inline static void list_remove( struct list *elem )
51 elem->next->prev = elem->prev;
52 elem->prev->next = elem->next;
55 /* get the next element */
56 inline static struct list *list_next( struct list *list, struct list *elem )
58 struct list *ret = elem->next;
59 if (elem->next == list) ret = NULL;
60 return ret;
63 /* get the previous element */
64 inline static struct list *list_prev( struct list *list, struct list *elem )
66 struct list *ret = elem->prev;
67 if (elem->prev == list) ret = NULL;
68 return ret;
71 /* get the first element */
72 inline static struct list *list_head( struct list *list )
74 return list_next( list, list );
77 /* get the last element */
78 inline static struct list *list_tail( struct list *list )
80 return list_prev( list, list );
83 /* initialize a list */
84 inline static void list_init( struct list *list )
86 list->next = list->prev = list;
89 /* iterate through the list */
90 #define LIST_FOR_EACH(cursor,list) \
91 for ((cursor) = (list)->next; (cursor) != (list); (cursor) = (cursor)->next)
93 /* macros for statically initialized lists */
94 #define LIST_INIT(list) { &(list), &(list) }
96 /* get pointer to object containing list element */
97 #define LIST_ENTRY(elem, type, field) \
98 ((type *)((char *)(elem) - (unsigned int)(&((type *)0)->field)))
100 #endif /* __WINE_SERVER_LIST_H */