about summary refs log tree commit homepage
path: root/compat-util.h
diff options
context:
space:
mode:
Diffstat (limited to 'compat-util.h')
-rw-r--r--compat-util.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/compat-util.h b/compat-util.h
new file mode 100644
index 0000000..60c4081
--- /dev/null
+++ b/compat-util.h
@@ -0,0 +1,40 @@
+#ifndef OS_COMPAT_H
+#define OS_COMPAT_H
+
+#define _LARGE_FILES
+#define _FILE_OFFSET_BITS 64
+#define _BSD_SOURCE /* for mincore */
+#define _XOPEN_SOURCE 600 /* for posix_fadvise */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <assert.h>
+
+#ifndef O_NOATIME
+#  define O_NOATIME 0
+#endif /* O_NOATIME */
+
+#define PAGE_MASK               (~(page_size() -1))
+#define PAGE_ALIGN(addr)        (((addr) + page_size() - 1) & PAGE_MASK)
+#define PAGE_ALIGN_DOWN(addr) \
+        (addr > page_size() ? PAGE_ALIGN(addr) - page_size() : 0)
+
+static inline size_t page_size(void)
+{
+        static size_t size;
+
+        if (!size)
+                size = sysconf(_SC_PAGESIZE);
+
+        return size;
+}
+
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
+
+#endif /* OS_COMPAT_H */