Initial "gts1" commit.
[tac_plus.git] / utils.h
diff --git a/utils.h b/utils.h
new file mode 100644 (file)
index 0000000..f8c39e8
--- /dev/null
+++ b/utils.h
@@ -0,0 +1,59 @@
+#ifndef UTILS_H
+#define UTILS_H 1
+
+#include "tac_plus.h"
+
+#include <sys/types.h>         /* for u_* */
+
+
+/* Configurable:
+ */
+#define TAC_LIST_PARANOIA 1
+
+
+/* Bidirectional lists */
+
+#ifdef TAC_LIST_PARANOIA
+#define TAC_LIST_MAGIC      (0xBEF78147U)
+#define TAC_LIST_NODE_MAGIC (0x297DA735U)
+#endif
+
+struct tac_list {
+#ifdef TAC_LIST_PARANOIA
+    unsigned _magic;
+#endif
+    struct tac_list_node *_head, *_tail;
+};
+
+struct tac_list_node {
+#ifdef TAC_LIST_PARANOIA
+    unsigned _magic;
+#endif
+    struct tac_list_node *_next, *_prev;
+    struct tac_list *_list;
+};
+
+
+extern void *tac_malloc TAC_ARGS((int size));
+extern void *tac_realloc TAC_ARGS((void *ptr, int size));
+extern void tac_exit TAC_ARGS((int status)) G_GNUC_NORETURN;
+extern char *tac_strdup TAC_ARGS((const char *p));
+extern char *tac_make_string TAC_ARGS((u_char *p, int len));
+extern const char *tac_find_substring TAC_ARGS((const char *substring, const char *string));
+extern int tac_lockfd TAC_ARGS((char *filename, int lockfd));
+
+/* Bidirectional lists: */
+
+extern void tac_list_init TAC_ARGS((struct tac_list *list));
+extern void tac_list_node_init TAC_ARGS((struct tac_list_node *node));
+extern struct tac_list *tac_list_node_get_list TAC_ARGS((struct tac_list_node *node));
+struct tac_list_node *tac_list_first_node TAC_ARGS((struct tac_list *list));
+struct tac_list_node *tac_list_last_node TAC_ARGS((struct tac_list *list));
+extern void tac_list_addhead TAC_ARGS((struct tac_list *list, struct tac_list_node *node));
+extern void tac_list_addtail TAC_ARGS((struct tac_list *list, struct tac_list_node *node));
+extern struct tac_list_node *tac_list_node_next TAC_ARGS((struct tac_list_node *node));
+extern struct tac_list_node *tac_list_node_prev TAC_ARGS((struct tac_list_node *node));
+extern void tac_list_node_remove TAC_ARGS((struct tac_list_node *node));
+
+
+#endif /* UTILS_H */