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