/usr/include/GTGList.h is in libgtg-dev 0.2-2+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | #ifndef GTG_LIST_H
#define GTG_LIST_H
struct gtg_list {
struct gtg_list *prev;
struct gtg_list *next;
};
typedef struct gtg_list* gtg_list_t;
/**
* \fn GTG_LIST_INIT(ptr)
* \brief initialize a list.
* \param ptr pointer to the list (gtg_list_t).
*/
#define GTG_LIST_INIT(ptr) \
do { \
(ptr)->prev = (ptr); \
(ptr)->next = (ptr); \
} while(0)
/**
* \fn GTG_LIST(name)
* \brief declare and initialize a list.
* \param name Name of the variable
*/
#define GTG_LIST(name) \
struct gtg_list name; \
GTG_LIST_INIT(&name)
/**
* \fn gtg_list_entry(ptr, type, member)
* \brief get the structure corresponding to a list entry
* \param ptr pointer to the list entry (gtg_list_t)
* \param type the type of the struct this is embedded in.
* \param member the name of the struct gtg_list member within the struct.
*/
#define gtg_list_entry(ptr, type, member) \
((type *)((char *)(ptr) - (char *)(&((type *)0)->member)))
/*
* Insert a new entry between two known consecutive entries.
*
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
static inline void __gtg_list_add(gtg_list_t lnew,
gtg_list_t prev,
gtg_list_t next)
{
next->prev = lnew;
lnew->next = next;
lnew->prev = prev;
prev->next = lnew;
}
/**
* \fn void gtg_list_add(gtg_list_t lnew, gtg_list_t head)
* \brief Insert a new entry after the specified head.
* \param lnew new entry to be added
* \param head list head to add it after
*/
static inline void gtg_list_add(gtg_list_t lnew, gtg_list_t head)
{
__gtg_list_add(lnew, head, head->next);
}
/**
* \fn void gtg_list_add_tail(gtg_list_t lnew, gtg_list_t head)
* \brief Insert a new entry before the specified head (ie. at the tail of the list).
* \param lnew new entry to be added
* \param head list head to add it after
*/
static inline void gtg_list_add_tail(gtg_list_t lnew, gtg_list_t head)
{
__gtg_list_add(lnew, head->prev, head);
}
/**
* Delete a list entry by making the prev/next entries
* point to each other.
*
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
static inline void __gtg_list_del(gtg_list_t prev, gtg_list_t next)
{
next->prev = prev;
prev->next = next;
}
/**
* \fn void gtg_list_del(gtg_list_t entry)
* \brief delete an entry from its list and reinitialize it.
* \param entry the element to delete from the list.
*/
static inline void gtg_list_del(gtg_list_t entry)
{
__gtg_list_del(entry->prev, entry->next);
GTG_LIST_INIT(entry);
}
/**
* \fn gtg_list_for_each(gtg_list_t pos, gtg_list_t head)
* \brief iterate over a list
* \param pos the gtg_list_t to use as a loop counter.
* \param head the head for the list.
*/
#define gtg_list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
/**
* \fn gtg_list_for_each_reverse(gtg_list_t pos, gtg_list_t head)
* \brief iterate over a list backwards
* \param pos the gtg_list_t to use as a loop counter.
* \param head the head for the list.
*/
#define gtg_list_for_each_reverse(pos, head) \
for (pos = (head)->prev; pos != (head); pos = pos->prev)
/**
* \fn gtg_list_for_each_safe(gtg_list_t pos, gtg_list_t n, gtg_list_t head)
* \brief iterate over a list safe against removal of list entry
* \param pos the gtg_list_t to use as a loop counter.
* \param n another gtg_list_t to use as temporary storage
* \param head the head for the list.
*/
#define gtg_list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
/**
* gtg_list_for_each_entry(pos, head, member)
* \brief iterate over list of given type
* \param pos the type * to use as a loop counter.
* \param head the head for the list.
* \param member the name of the struct gtg_list member within the struct.
*/
#define gtg_list_for_each_entry(pos, head, member) \
for (pos = gtg_list_entry((head)->next, typeof(*pos), member); \
&pos->member != (head); \
pos = gtg_list_entry(pos->member.next, typeof(*pos), member))
/**
* gtg_list_for_each_entry_safe(pos, n, head, member)
* \brief iterate over list of given type safe against removal of list entry
* \param pos the type * to use as a loop counter.
* \param n another type * to use as temporary storage
* \param head the head for the list.
* \param member the name of the struct gtg_list member within the struct.
*/
#define gtg_list_for_each_entry_safe(pos, n, head, member) \
for (pos = gtg_list_entry((head)->next, typeof(*pos), member), \
n = gtg_list_entry(pos->member.next, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = gtg_list_entry(n->member.next, typeof(*n), member))
static inline int gtg_list_size(gtg_list_t l)
{
int res = 0;
gtg_list_t ptr = NULL;
gtg_list_for_each(ptr, l)
res++;
return res;
}
#endif /* GTG_LIST_H */
|