map.h 1.13 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

26 27 28 29
#ifdef __amigaos4__
#define MAP_FAILED 0
#endif

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

38 39 40 41
#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)
42

Vicent Marti committed
43 44
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);
45 46

#endif /* INCLUDE_map_h__ */