deps/libgit2/src/util/unix/map.c

filter: Statementstmt 70.5% 24 / 34 Branchbran 45.8% 11 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 60.3% 35 / 58 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« deps/libgit2/src/libgit2/rebase.c ↑ Summary deps/libgit2/src/libgit2/reset.c »
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
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.
6 */
7  
8 #include "git2_util.h"
9  
10 #if !defined(GIT_WIN32) && !defined(NO_MMAP)
11  
12 #include "map.h"
13 #include <sys/mman.h>
14 #include <unistd.h>
15 #include <errno.h>
16  
17 87 int git__page_size(size_t *page_size)
18 {
19 87 long sc_page_size = sysconf(_SC_PAGE_SIZE);
20 87 ▶ if (sc_page_size < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (sc_page_size < 0) { 0 87 87
21 0 git_error_set(GIT_ERROR_OS, "can't determine system page size");
22 0 return -1;
23 }
24 87 *page_size = (size_t) sc_page_size;
25 87 return 0;
26 }
27  
28 0 int git__mmap_alignment(size_t *alignment)
29 {
30 0 return git__page_size(alignment);
31 }
32  
33 60 int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset)
34 {
35 60 int mprot = PROT_READ;
36 60 int mflag = 0;
37  
38 60 ▶ GIT_MMAP_VALIDATE(out, len, prot, flags);
Branch: 5 branches
BranchTrueFalseTotal
GIT_MMAP_VALIDATE(out, len, prot, flags); 60 0 60
GIT_MMAP_VALIDATE(out, len, prot, flags); 0 60 60
GIT_MMAP_VALIDATE(out, len, prot, flags); 60 0 60
GIT_MMAP_VALIDATE(out, len, prot, flags); 0 60 60
GIT_MMAP_VALIDATE(out, len, prot, flags); 0 60 60
39  
40 60 out->data = NULL;
41 60 out->len = 0;
42  
43 60 ▶ if (prot & GIT_PROT_WRITE)
Branch: 1 branch
BranchTrueFalseTotal
if (prot & GIT_PROT_WRITE) 0 60 60
44 0 mprot |= PROT_WRITE;
45  
46 60 ▶ if ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)
Branch: 1 branch
BranchTrueFalseTotal
if ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED) 60 0 60
47 60 mflag = MAP_SHARED;
48 0 ▶ else if ((flags & GIT_MAP_TYPE) == GIT_MAP_PRIVATE)
Branch: 1 branch
BranchTrueFalseTotal
else if ((flags & GIT_MAP_TYPE) == GIT_MAP_PRIVATE) 0 0 0
49 0 mflag = MAP_PRIVATE;
50 else
51 0 mflag = MAP_SHARED;
52  
53 60 out->data = mmap(NULL, len, mprot, mflag, fd, offset);
54  
55 60 ▶ if (!out->data || out->data == MAP_FAILED) {
Branch: 2 branches
BranchTrueFalseTotal
if (!out->data || out->data == MAP_FAILED) { 60 0 60
if (!out->data || out->data == MAP_FAILED) { 0 60 60
56 0 git_error_set(GIT_ERROR_OS, "failed to mmap. Could not write data");
57 0 return -1;
58 }
59  
60 60 out->len = len;
61  
62 60 return 0;
63 }
64  
65 60 int p_munmap(git_map *map)
66 {
67 60 ▶ GIT_ASSERT_ARG(map);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(map); 0 60 60
68 60 munmap(map->data, map->len);
69 60 map->data = NULL;
70 60 map->len = 0;
71  
72 60 return 0;
73 }
74  
75 #endif
76  
« deps/libgit2/src/libgit2/rebase.c ↑ Summary deps/libgit2/src/libgit2/reset.c »