Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2012-12-05 23:47:19 +0400
committerVicent Martí <vicent@github.com>2012-12-05 23:47:19 +0400
commite05ca13f1f3550f59790c0f992841abceee1b4c5 (patch)
treea01c119011d0c6020c9288096d09ed055c475bd8 /src/common.h
parenta541eafa606b58e7ce3df8e496da8e032fdb74ec (diff)
parentee1c33b146a366260a4648b1f29f470fedaca0fa (diff)
Merge pull request #1115 from ben/struct-versions
Version info for public structs
Diffstat (limited to 'src/common.h')
-rw-r--r--src/common.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/common.h b/src/common.h
index b3b551508..3152669df 100644
--- a/src/common.h
+++ b/src/common.h
@@ -65,6 +65,33 @@ void giterr_set(int error_class, const char *string, ...);
*/
int giterr_set_regex(const regex_t *regex, int error_code);
+/**
+ * Check a versioned structure for validity
+ */
+GIT_INLINE(bool) giterr__check_version(const void *structure, unsigned int expected_max, const char *name)
+{
+ if (!structure)
+ return true;
+
+ unsigned int actual = *(const unsigned int*)structure;
+ if (actual > 0 && actual <= expected_max)
+ return true;
+
+ giterr_set(GITERR_INVALID, "Invalid version %d on %s", actual, name);
+ return false;
+}
+#define GITERR_CHECK_VERSION(S,V,N) if (!giterr__check_version(S,V,N)) return -1
+
+/**
+ * Initialize a structure with a version.
+ */
+GIT_INLINE(void) git__init_structure(void *structure, size_t len, unsigned int version)
+{
+ memset(structure, 0, len);
+ *((int*)structure) = version;
+}
+#define GIT_INIT_STRUCTURE(S,V) git__init_structure(S, sizeof(*S), V)
+
/* NOTE: other giterr functions are in the public errors.h header file */
#include "util.h"