1 /*****************************************************************************\
3 * | || | ___ | |_ _ __ | | _ _ __ _ |_ ) *
4 * | __ |/ _ \| _|| '_ \| || || |/ _` | / / *
5 * |_||_|\___/ \__|| .__/|_| \_,_|\__, |/___| *
7 \*****************************************************************************/
13 #include <sys/types.h>
17 #include "filemap_utils.h"
20 * Basic open/mmap wrapper to make things simpler.
22 * @1 Filename of the mmaped file
23 * @2 Pointer to filemap structure
25 * Returns: 0 if success, 1 otherwise
27 int map_file(const char *filename
, struct filemap_t
*filemap
) {
30 filemap
->fd
= open(filename
, O_RDONLY
);
31 if (filemap
->fd
== -1) {
35 if (fstat(filemap
->fd
, &statbuf
)) {
40 filemap
->size
= statbuf
.st_size
;
42 filemap
->map
= mmap(0, filemap
->size
, PROT_READ
, MAP_SHARED
, filemap
->fd
, 0);
43 if (filemap
->map
== MAP_FAILED
) {
52 * Basic close/munmap wrapper.
54 * @1 Pointer to filemap structure
58 int unmap_file(struct filemap_t
*filemap
) {
59 munmap(filemap
->map
, filemap
->size
);