Add common c-utils, make flatdb aligned on disk
[tedtools.git] / tools.h
diff --git a/tools.h b/tools.h
index d70d14d..6db856d 100644 (file)
--- a/tools.h
+++ b/tools.h
@@ -39,4 +39,19 @@ char*     xtostr(u_int32_t x);
 
 double timediff(struct timeval *begin, struct timeval *end);
 double elapsedtime(struct timeval *begin);
+
+#ifndef offsetof
+#define offsetof(type, field)   ((int) &((type *)0)->field)
+#endif   /* offsetof */
+
+#ifndef TYPEALIGN
+#define TYPEALIGN(ALIGNVAL,LEN)  \
+        (((long) (LEN) + ((ALIGNVAL) - 1)) & ~((long) ((ALIGNVAL) - 1)))
+
+#define SHORTALIGN(LEN)                 TYPEALIGN(sizeof(int16), (LEN))
+#define INTALIGN(LEN)                   TYPEALIGN(sizeof(int32), (LEN))
+#define MAXALIGN(LEN)                   TYPEALIGN(sizeof(int64), (LEN))
+#define PTRALIGN(LEN)                   TYPEALIGN(sizeof(void*), (LEN))
+#endif
+
 #endif