path: root/git-compat-util.h
diff options
authorNicolas Pitre <>2007-04-09 05:06:29 (GMT)
committerJunio C Hamano <>2007-04-10 19:48:14 (GMT)
commit8723f216263ba4a0f06be7b93fada863c0931e09 (patch)
tree6d357724c891ce009a8c7ae1a0a4083bc39ff1f5 /git-compat-util.h
parent57059091fad25427bce9b3d47e073ce0518d164b (diff)
make overflow test on delta base offset work regardless of variable size
This patch introduces the MSB() macro to obtain the desired number of most significant bits from a given variable independently of the variable type. It is then used to better implement the overflow test on the OBJ_OFS_DELTA base offset variable with the property of always working correctly regardless of the type/size of that variable. Signed-off-by: Nicolas Pitre <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'git-compat-util.h')
1 files changed, 8 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index 139fc19..bcfcb35 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -13,6 +13,14 @@
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
+#ifdef __GNUC__
+#define TYPEOF(x) (__typeof__(x))
+#define TYPEOF(x)
+#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (sizeof(x) * 8 - (bits))))
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD needs 600 for S_ISLNK() */
#define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */