-#define silc_list_add(list, entry) __silc_list_add(&(list), entry)
-static inline void __silc_list_add(SilcList *list, void *data)
-{
- if (list->head == NULL)
- list->head = data;
- else
- *list_next(list, list->tail) = data;
-
- list->tail = data;
- *list_next(list, data) = NULL;
-}
+#define silc_list_add(list, entry) \
+do { \
+ if (!(list).head) \
+ (list).head = (entry); \
+ else \
+ *__silc_list_next(list, (list).tail) = (entry); \
+ if ((list).prev_set) \
+ *__silc_list_prev(list, entry) = (list).tail; \
+ (list).tail = (entry); \
+ *__silc_list_next(list, entry) = NULL; \
+ (list).count++; \
+} while(0)
+
+/****f* silcutil/SilcList/silc_list_insert
+ *
+ * SYNOPSIS
+ *
+ * #define silc_list_insert(list, current, entry) ...
+ *
+ * DESCRIPTION
+ *
+ * Insert new entry indicated by `entry' after the entry `current'
+ * to the list indicated by `list'. If `current' is NULL, then the
+ * `entry' is added at the head of the list. Use the silc_list_add
+ * to add at the end of the list.
+ *
+ ***/
+#define silc_list_insert(list, current, entry) \
+do { \
+ if (!(current)) { \
+ if ((list).head) \
+ *__silc_list_next(list, entry) = (list).head; \
+ else \
+ *__silc_list_next(list, entry) = NULL; \
+ if ((list).prev_set && (list).head) \
+ *__silc_list_prev(list, (list).head) = entry; \
+ if (!(list).tail) \
+ (list).tail = (entry); \
+ (list).head = (entry); \
+ if ((list).prev_set) \
+ *__silc_list_prev(list, entry) = NULL; \
+ } else { \
+ *__silc_list_next(list, entry) = *__silc_list_next(list, current); \
+ *__silc_list_next(list, current) = entry; \
+ if ((list).prev_set) { \
+ *__silc_list_prev(list, entry) = current; \
+ if (*__silc_list_next(list, entry)) \
+ *__silc_list_prev(list, *__silc_list_next(list, entry)) = entry; \
+ } \
+ if ((list).tail == (current)) \
+ (list).tail = (entry); \
+ } \
+ (list).count++; \
+} while(0)