]>
git.proxmox.com Git - libgit2.git/blob - src/unix/map.c
2 * Copyright (C) the libgit2 contributors. All rights reserved.
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>
9 #if !defined(GIT_WIN32) && !defined(NO_MMAP)
16 long git__page_size(void)
18 return sysconf(_SC_PAGE_SIZE
);
21 int p_mmap(git_map
*out
, size_t len
, int prot
, int flags
, int fd
, git_off_t offset
)
26 GIT_MMAP_VALIDATE(out
, len
, prot
, flags
);
31 if (prot
& GIT_PROT_WRITE
)
33 else if (prot
& GIT_PROT_READ
)
36 if ((flags
& GIT_MAP_TYPE
) == GIT_MAP_SHARED
)
38 else if ((flags
& GIT_MAP_TYPE
) == GIT_MAP_PRIVATE
)
43 out
->data
= mmap(NULL
, len
, mprot
, mflag
, fd
, offset
);
45 if (!out
->data
|| out
->data
== MAP_FAILED
) {
46 giterr_set(GITERR_OS
, "Failed to mmap. Could not write data");
55 int p_munmap(git_map
*map
)
58 munmap(map
->data
, map
->len
);