File Coverage

deps/libgit2/src/libgit2/common.h
Criterion Covered Total %
statement 0 8 0.0
branch 0 6 0.0
condition n/a
subroutine n/a
pod n/a
total 0 14 0.0


line stmt bran cond sub pod time code
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             #ifndef INCLUDE_common_h__
8             #define INCLUDE_common_h__
9              
10             #include "git2_util.h"
11             #include "errors.h"
12              
13             /*
14             * Include the declarations for deprecated functions; this ensures
15             * that they're decorated with the proper extern/visibility attributes.
16             */
17             #include "git2/deprecated.h"
18              
19             #include "posix.h"
20              
21             /**
22             * Initialize a structure with a version.
23             */
24             GIT_INLINE(void) git__init_structure(void *structure, size_t len, unsigned int version)
25             {
26             memset(structure, 0, len);
27             *((int*)structure) = version;
28             }
29             #define GIT_INIT_STRUCTURE(S,V) git__init_structure(S, sizeof(*S), V)
30              
31             #define GIT_INIT_STRUCTURE_FROM_TEMPLATE(PTR,VERSION,TYPE,TPL) do { \
32             TYPE _tmpl = TPL; \
33             GIT_ERROR_CHECK_VERSION(&(VERSION), _tmpl.version, #TYPE); \
34             memcpy((PTR), &_tmpl, sizeof(_tmpl)); } while (0)
35              
36             /**
37             * Check a versioned structure for validity
38             */
39 0           GIT_INLINE(int) git_error__check_version(const void *structure, unsigned int expected_max, const char *name)
40             {
41             unsigned int actual;
42              
43 0 0         if (!structure)
44 0           return 0;
45              
46 0           actual = *(const unsigned int*)structure;
47 0 0         if (actual > 0 && actual <= expected_max)
    0          
48 0           return 0;
49              
50 0           git_error_set(GIT_ERROR_INVALID, "invalid version %d on %s", actual, name);
51 0           return -1;
52             }
53             #define GIT_ERROR_CHECK_VERSION(S,V,N) if (git_error__check_version(S,V,N) < 0) return -1
54              
55             #endif