pcu.git  about / heads / tags
page cache utilities for Linux
blob 60c40814df1e4e71ada1f6a55e9e116eab564b4f 861 bytes (raw)
$ git show v0.1.0:compat-util.h	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 */

git clone https://yhbt.net/pcu.git