map.h 1.09 KB
Newer Older
Vicent Marti committed
1
/*
schu committed
2
 * Copyright (C) 2009-2012 the libgit2 contributors
Vicent Marti committed
3 4 5 6
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */
7 8 9 10 11 12
#ifndef INCLUDE_map_h__
#define INCLUDE_map_h__

#include "common.h"


Vicent Marti committed
13
/* p_mmap() prot values */
Vicent Marti committed
14 15
#define GIT_PROT_NONE 0x0
#define GIT_PROT_READ 0x1
16
#define GIT_PROT_WRITE 0x2
Vicent Marti committed
17
#define GIT_PROT_EXEC 0x4
18 19

/* git__mmmap() flags values */
Vicent Marti committed
20 21
#define GIT_MAP_FILE	0
#define GIT_MAP_SHARED 1
22
#define GIT_MAP_PRIVATE 2
Vicent Marti committed
23 24
#define GIT_MAP_TYPE	0xf
#define GIT_MAP_FIXED	0x10
25

Vicent Marti committed
26 27 28
typedef struct { /* memory mapped buffer	*/
	void *data; /* data bytes			*/
	size_t len; /* data length			*/
29
#ifdef GIT_WIN32
Vicent Marti committed
30
	HANDLE fmh; /* file mapping handle */
31 32 33
#endif
} git_map;

34 35 36 37
#define GIT_MMAP_VALIDATE(out, len, prot, flags) do { \
	assert(out != NULL && len > 0); \
	assert((prot & GIT_PROT_WRITE) || (prot & GIT_PROT_READ)); \
	assert((flags & GIT_MAP_FIXED) == 0); } while (0)
38

Vicent Marti committed
39 40
extern int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset);
extern int p_munmap(git_map *map);
41 42

#endif /* INCLUDE_map_h__ */