6 #define _FILE_OFFSET_BITS 64
7 #define _BSD_SOURCE /* for mincore */
8 #define _XOPEN_SOURCE 600 /* for posix_fadvise */
23 #endif /* O_NOATIME */
25 #define PAGE_MASK (~(page_size() -1))
26 #define PAGE_ALIGN(addr) (((addr) + page_size() - 1) & PAGE_MASK)
27 #define PAGE_ALIGN_DOWN(addr) \
28 (addr > page_size() ? PAGE_ALIGN(addr) - page_size() : 0)
30 static inline size_t page_size(void)
35 size
= sysconf(_SC_PAGESIZE
);
40 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
43 * converts a C string to a non-negative off_t value, taking base into
44 * account. On error, it'll return a negative value and set errno
47 static inline off_t
cstr_to_off_t(const char *nptr
, char **endptr
, int base
)
49 if (sizeof(long) == 8 || (sizeof(long) == 4 && sizeof(off_t
) == 4))
50 return (off_t
)strtol(nptr
, endptr
, base
);
51 else if (sizeof(off_t
) == 8 && sizeof(long) == 4)
52 return (off_t
)strtoll(nptr
, endptr
, base
);
54 fprintf(stderr
, "unrecognized sizes:\n\toff_t: %u\n\tlong: %u\n",
55 (unsigned)sizeof(off_t
), (unsigned)sizeof(long));
59 #endif /* OS_COMPAT_H */