enable sysv ipc and fast share modes on OSF1
[Samba.git] / source / ubi_dLinkList.h
blob1facf92d3b1c1843cb66874943b1d03679e24edc
1 #ifndef ubi_dLinkList_H
2 #define ubi_dLinkList_H
3 /* ========================================================================== **
4 * ubi_dLinkList.h
6 * Copyright (C) 1997 by Christopher R. Hertel
8 * Email: crh@ubiqx.mn.org
9 * -------------------------------------------------------------------------- **
10 * This module implements simple doubly-linked lists.
11 * -------------------------------------------------------------------------- **
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Library General Public
15 * License as published by the Free Software Foundation; either
16 * version 2 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Library General Public License for more details.
23 * You should have received a copy of the GNU Library General Public
24 * License along with this library; if not, write to the Free
25 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * -------------------------------------------------------------------------- **
29 * Revision 0.3 1997/10/15 03:04:31 crh
30 * Added some handy type casting to the macros. Added AddHere and RemThis
31 * macros.
33 * Revision 0.2 1997/10/08 03:08:16 crh
34 * Fixed a few forgotten link-ups in Insert(), and fixed the AddHead()
35 * macro, which was passing the wrong value for <After> to Insert().
37 * Revision 0.1 1997/10/07 04:34:38 crh
38 * Initial Revision.
41 * ========================================================================== **
44 #include <stdlib.h>
47 /* ========================================================================== **
48 * Typedefs...
50 * ubi_dlNode - This is the basic node structure.
51 * ubi_dlNodePtr - Pointer to a node.
52 * ubi_dlList - This is the list header structure.
53 * ubi_dlListPtr - Pointer to a List (i.e., a list header structure).
57 typedef struct ubi_dlListNode
59 struct ubi_dlListNode *Next;
60 struct ubi_dlListNode *Prev;
61 } ubi_dlNode;
63 typedef ubi_dlNode *ubi_dlNodePtr;
65 typedef struct
67 ubi_dlNodePtr Head;
68 ubi_dlNodePtr Tail;
69 unsigned long count;
70 } ubi_dlList;
72 typedef ubi_dlList *ubi_dlListPtr;
74 /* ========================================================================== **
75 * Macros...
77 * ubi_dlAddHead - Add a new node at the head of the list.
78 * ubi_dlAddTail - Add a new node at the tail of the list.
79 * ubi_dlAddHere - Add a node following the given node.
80 * ubi_dlRemHead - Remove the node at the head of the list, if any.
81 * ubi_dlRemTail - Remove the node at the tail of the list, if any.
82 * ubi_dlRemThis - Remove the indicated node.
83 * ubi_dlFirst - Return a pointer to the first node in the list, if any.
84 * ubi_dlLast - Return a pointer to the last node in the list, if any.
85 * ubi_dlNext - Given a node, return a pointer to the next node.
86 * ubi_dlPrev - Given a node, return a pointer to the previous node.
88 * Note that all of these provide type casting of the parameters. The
89 * Add and Rem macros are nothing more than nice front-ends to the
90 * Insert and Remove operations.
94 #define ubi_dlAddHead( L, N ) \
95 ubi_dlInsert( (ubi_dlListPtr)(L), (ubi_dlNodePtr)(N), NULL )
97 #define ubi_dlAddTail( L, N ) \
98 ubi_dlInsert( (ubi_dlListPtr)(L), \
99 (ubi_dlNodePtr)(N), \
100 (((ubi_dlListPtr)(L))->Tail) )
102 #define ubi_dlAddHere( L, N, P ) \
103 ubi_dlInsert( (ubi_dlListPtr)(L), \
104 (ubi_dlNodePtr)(N), \
105 (ubi_dlNodePtr)(P) )
107 #define ubi_dlRemHead( L ) ubi_dlRemove( (ubi_dlListPtr)(L), \
108 (((ubi_dlListPtr)(L))->Head) )
110 #define ubi_dlRemTail( L ) ubi_dlRemove( (ubi_dlListPtr)(L), \
111 (((ubi_dlListPtr)(L))->Tail) )
113 #define ubi_dlRemThis( L, N ) ubi_dlRemove( (ubi_dlListPtr)(L), \
114 (ubi_dlNodePtr)(N) )
116 #define ubi_dlFirst( L ) (((ubi_dlListPtr)(L))->Head)
118 #define ubi_dlLast( L ) (((ubi_dlListPtr)(L))->Tail)
120 #define ubi_dlNext( N ) (((ubi_dlNodePtr)(N))->Next)
122 #define ubi_dlPrev( N ) (((ubi_dlNodePtr)(N))->Prev)
125 /* ========================================================================== **
126 * Function prototypes...
129 ubi_dlListPtr ubi_dlInitList( ubi_dlListPtr ListPtr );
130 /* ------------------------------------------------------------------------ **
131 * Initialize a doubly-linked list header.
133 * Input: ListPtr - A pointer to the list structure that is to be
134 * initialized for use.
136 * Output: A pointer to the initialized list header (i.e., same as
137 * <ListPtr>).
139 * ------------------------------------------------------------------------ **
142 ubi_dlNodePtr ubi_dlInsert( ubi_dlListPtr ListPtr,
143 ubi_dlNodePtr New,
144 ubi_dlNodePtr After );
145 /* ------------------------------------------------------------------------ **
146 * Insert a new node into the list.
148 * Input: ListPtr - A pointer to the list into which the node is to
149 * be inserted.
150 * New - Pointer to the new node.
151 * After - NULL, or a pointer to a node that is already in the
152 * list.
153 * If NULL, then <New> will be added at the head of the
154 * list, else it will be added following <After>.
156 * Output: A pointer to the node that was inserted into the list (i.e.,
157 * the same as <New>).
159 * ------------------------------------------------------------------------ **
162 ubi_dlNodePtr ubi_dlRemove( ubi_dlListPtr ListPtr, ubi_dlNodePtr Old );
163 /* ------------------------------------------------------------------------ **
164 * Remove a node from the list.
166 * Input: ListPtr - A pointer to the list from which <Old> is to be
167 * removed.
168 * Old - A pointer to the node that is to be removed from the
169 * list.
171 * Output: A pointer to the node that was removed (i.e., <Old>).
173 * ------------------------------------------------------------------------ **
177 /* ================================ The End ================================= */
178 #endif /* ubi_dLinkList_H */