60c40814df1e4e71ada1f6a55e9e116eab564b4f
[pcu.git] / compat-util.h
blob60c40814df1e4e71ada1f6a55e9e116eab564b4f
1 #ifndef OS_COMPAT_H
2 #define OS_COMPAT_H
4 #define _LARGE_FILES
5 #define _FILE_OFFSET_BITS 64
6 #define _BSD_SOURCE /* for mincore */
7 #define _XOPEN_SOURCE 600 /* for posix_fadvise */
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <fcntl.h>
11 #include <unistd.h>
12 #include <sys/mman.h>
13 #include <string.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <errno.h>
17 #include <assert.h>
19 #ifndef O_NOATIME
20 # define O_NOATIME 0
21 #endif /* O_NOATIME */
23 #define PAGE_MASK (~(page_size() -1))
24 #define PAGE_ALIGN(addr) (((addr) + page_size() - 1) & PAGE_MASK)
25 #define PAGE_ALIGN_DOWN(addr) \
26 (addr > page_size() ? PAGE_ALIGN(addr) - page_size() : 0)
28 static inline size_t page_size(void)
30 static size_t size;
32 if (!size)
33 size = sysconf(_SC_PAGESIZE);
35 return size;
38 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
40 #endif /* OS_COMPAT_H */