]>
git.proxmox.com Git - libgit2.git/blob - src/unix/map.c
2 * Copyright (C) 2009-2011 the libgit2 contributors
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
7 #include <git2/common.h>
15 int p_mmap(git_map
*out
, size_t len
, int prot
, int flags
, int fd
, git_off_t offset
)
20 assert((out
!= NULL
) && (len
> 0));
22 if ((out
== NULL
) || (len
== 0)) {
24 return git__throw(GIT_ERROR
, "Failed to mmap. No map or zero length");
30 if (prot
& GIT_PROT_WRITE
)
32 else if (prot
& GIT_PROT_READ
)
36 return git__throw(GIT_ERROR
, "Failed to mmap. Invalid protection parameters");
39 if ((flags
& GIT_MAP_TYPE
) == GIT_MAP_SHARED
)
41 else if ((flags
& GIT_MAP_TYPE
) == GIT_MAP_PRIVATE
)
44 if (flags
& GIT_MAP_FIXED
) {
46 return git__throw(GIT_ERROR
, "Failed to mmap. FIXED not set");
49 out
->data
= mmap(NULL
, len
, mprot
, mflag
, fd
, offset
);
50 if (!out
->data
|| out
->data
== MAP_FAILED
)
51 return git__throw(GIT_EOSERR
, "Failed to mmap. Could not write data");
57 int p_munmap(git_map
*map
)
62 return git__throw(GIT_ERROR
, "Failed to munmap. Map does not exist");
64 munmap(map
->data
, map
->len
);