Annotation of src/usr.bin/sudo/list.h, Revision 1.2
1.1 millert 1: /*
2: * Copyright (c) 2007 Todd C. Miller <Todd.Miller@courtesan.com>
3: *
4: * Permission to use, copy, modify, and distribute this software for any
5: * purpose with or without fee is hereby granted, provided that the above
6: * copyright notice and this permission notice appear in all copies.
7: *
8: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15: */
16:
17: #ifndef _SUDO_LIST_H
18: #define _SUDO_LIST_H
19:
20: /*
21: * Convenience macro for declaring a list head.
22: */
23: #ifdef __STDC__
24: #define TQ_DECLARE(n) \
25: struct n##_list { \
26: struct n *first; \
27: struct n *last; \
28: };
29: #else
30: #define TQ_DECLARE(n) \
31: struct n/**/_list { \
32: struct n *first; \
33: struct n *last; \
34: };
35: #endif
36:
37: /*
38: * Foreach loops: forward and reverse
39: */
40: #undef tq_foreach_fwd
41: #define tq_foreach_fwd(h, v) \
42: for ((v) = (h)->first; (v) != NULL; (v) = (v)->next)
43:
44: #undef tq_foreach_rev
45: #define tq_foreach_rev(h, v) \
46: for ((v) = (h)->last; (v) != NULL; (v) = (v)->prev)
47:
48: /*
49: * Init a list head.
50: */
51: #undef tq_init
52: #define tq_init(h) do { \
53: (h)->first = NULL; \
54: (h)->last = NULL; \
55: } while (0)
56:
57: /*
58: * Simple macros to avoid exposing first/last and prev/next.
59: */
60: #undef tq_empty
61: #define tq_empty(h) ((h)->first == NULL)
62:
63: #undef tq_first
64: #define tq_first(h) ((h)->first)
65:
66: #undef tq_last
67: #define tq_last(h) ((h)->last)
68:
69: #undef list_next
70: #define list_next(e) ((e)->next)
71:
72: #undef list_prev
73: #define list_prev(e) ((e)->prev)
74:
75: /*
76: * Prototypes for list.c
77: */
78: void *tq_pop __P((void *));
79: void tq_append __P((void *, void *));
80: void list_append __P((void *, void *));
81: void list2tq __P((void *, void *));
82:
83: #endif /* _SUDO_LIST_H */