diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-10-24 18:41:26 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-10-24 18:41:26 -0700 |
commit | e69018abd4d720324992d4fe276da8405182c108 (patch) | |
tree | 5cb36cbf7fd79a79a00fcf842290e3c9b02d47b4 /compat-util.h | |
download | pcu-e69018abd4d720324992d4fe276da8405182c108.tar.gz |
initial v0.1.0
Diffstat (limited to 'compat-util.h')
-rw-r--r-- | compat-util.h | 40 |
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 */ |