1 #include "compat-util.h"
3 static void mincore_stats(const char *path
)
13 if ((fd
= open(path
, O_RDONLY
)) < 0) {
14 fprintf(stderr
, "%s: open(): %s\n", path
, strerror(errno
));
18 if (fstat(fd
, &sb
) < 0) {
19 fprintf(stderr
, "%s: fstat(%d): %s\n",
20 path
, fd
, strerror(errno
));
24 vec_len
= (sb
.st_size
+ page_size() - 1) / page_size();
25 if (!(vec
= malloc(vec_len
))) {
26 fprintf(stderr
, "%s: malloc(%lu): %s\n",
27 path
, (unsigned long)vec_len
, strerror(errno
));
31 map_len
= PAGE_ALIGN(sb
.st_size
);
32 if (!(map
= mmap(NULL
, map_len
, PROT_READ
, MAP_SHARED
, fd
, 0))) {
33 fprintf(stderr
, "%s: mmap(%lu): %s\n",
34 path
, (unsigned long)vec_len
, strerror(errno
));
38 if (mincore(map
, map_len
, vec
) < 0) {
39 fprintf(stderr
, "%s: mincore(%lu): %s\n",
40 path
, (unsigned long)vec_len
, strerror(errno
));
44 for (i
= 0; i
< vec_len
; ++i
)
45 printf("%s: [%08lu] %x\n",
46 path
, (unsigned long)i
,
56 int main(int argc
, char * const argv
[])
60 for (i
= 1; i
< argc
; ++i
)
61 mincore_stats(argv
[i
]);