1 #ifndef _RING_H_INCLUDED_
2 #define _RING_H_INCLUDED_
3 
4 /*++
5 /* NAME
6 /*	ring 3h
7 /* SUMMARY
8 /*	circular list management
9 /* SYNOPSIS
10 /*	#include <ring.h>
11 /* DESCRIPTION
12 /* .nf
13 
14  /*
15   * External interface.
16   */
17 typedef struct RING RING;
18 
19 struct RING {
20     RING   *succ;			/* successor */
21     RING   *pred;			/* predecessor */
22 };
23 
24 extern void ring_init(RING *);
25 extern void ring_prepend(RING *, RING *);
26 extern void ring_append(RING *, RING *);
27 extern void ring_detach(RING *);
28 
29 #define ring_succ(c) ((c)->succ)
30 #define ring_pred(c) ((c)->pred)
31 
32 #define RING_FOREACH(entry, head) \
33     for (entry = ring_succ(head); entry != (head); entry = ring_succ(entry))
34 
35  /*
36   * Typically, an application will embed a RING structure into a larger
37   * structure that also contains application-specific members. This approach
38   * gives us the best of both worlds. The application can still use the
39   * generic RING primitives for manipulating RING structures. The macro below
40   * transforms a pointer from RING structure to the structure that contains
41   * it.
42   */
43 #define RING_TO_APPL(ring_ptr,app_type,ring_member) \
44     ((app_type *) (((char *) (ring_ptr)) - offsetof(app_type,ring_member)))
45 
46 /* LICENSE
47 /* .ad
48 /* .fi
49 /*	The Secure Mailer license must be distributed with this software.
50 /* AUTHOR(S)
51 /*	Wietse Venema
52 /*	IBM T.J. Watson Research
53 /*	P.O. Box 704
54 /*	Yorktown Heights, NY 10598, USA
55 /* LAST MODIFICATION
56 /*	Tue Jan 28 16:50:20 EST 1997
57 /*--*/
58 
59 #endif
60