forked from dfaure-kdab/desktop-file-index
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckpages.c
32 lines (29 loc) · 774 Bytes
/
checkpages.c
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
#include <sys/mman.h>
#include <glib.h>
int
main (int argc, char **argv)
{
GError *error = NULL;
GMappedFile *mapped;
gpointer contents;
gint n_pages;
guchar *pages;
gsize size;
gint i;
mapped = g_mapped_file_new (argv[1], FALSE, &error);
g_assert_no_error (error);
contents = g_mapped_file_get_contents (mapped);
size = g_mapped_file_get_length (mapped);
n_pages = (size + 4095) / 4096;
pages = g_new0 (guchar, n_pages);
mincore (contents, size, pages);
for (i = 0; i < n_pages; i++)
g_print ("%c", (pages[i] & 1) ? '#' : '.');
g_print ("\n");
madvise (contents, size, MADV_DONTNEED);
mincore (contents, size, pages);
for (i = 0; i < n_pages; i++)
g_print ("%c", (pages[i] & 1) ? '#' : '.');
g_print ("\n");
return 0;
}