]>
git.proxmox.com Git - libgit2.git/blob - src/unix/map.c
2 * Copyright (C) 2009-2012 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>
17 int p_mmap(git_map
*out
, size_t len
, int prot
, int flags
, int fd
, git_off_t offset
)
22 GIT_MMAP_VALIDATE(out
, len
, prot
, flags
);
28 if (prot
& GIT_PROT_WRITE
)
30 else if (prot
& GIT_PROT_READ
)
33 if ((flags
& GIT_MAP_TYPE
) == GIT_MAP_SHARED
)
35 else if ((flags
& GIT_MAP_TYPE
) == GIT_MAP_PRIVATE
)
38 out
->data
= mmap(NULL
, len
, mprot
, mflag
, fd
, offset
);
40 if ((prot
& GIT_PROT_WRITE
) && ((flags
& GIT_MAP_TYPE
) == GIT_MAP_SHARED
)) {
41 printf("Trying to map shared-writeable file!!!\n");
44 if(out
->data
= malloc(len
)) {
45 lseek(fd
, offset
, SEEK_SET
);
46 p_read(fd
, out
->data
, len
);
50 if (!out
->data
|| out
->data
== MAP_FAILED
) {
51 giterr_set(GITERR_OS
, "Failed to mmap. Could not write data");
60 int p_munmap(git_map
*map
)
64 munmap(map
->data
, map
->len
);