]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-compat-util.h
introduce container_of macro
[thirdparty/git.git] / git-compat-util.h
index cc0e7e97334ec90a355f9c8eb088c6810a91193c..4cc2c8283ac91d75bc23096b9f3cdfc00c391743 100644 (file)
@@ -1,6 +1,15 @@
 #ifndef GIT_COMPAT_UTIL_H
 #define GIT_COMPAT_UTIL_H
 
+#ifdef USE_MSVC_CRTDBG
+/*
+ * For these to work they must appear very early in each
+ * file -- before most of the standard header files.
+ */
+#include <stdlib.h>
+#include <crtdbg.h>
+#endif
+
 #define _FILE_OFFSET_BITS 64
 
 
@@ -1303,4 +1312,14 @@ void unleak_memory(const void *ptr, size_t len);
  */
 #include "banned.h"
 
+/*
+ * container_of - Get the address of an object containing a field.
+ *
+ * @ptr: pointer to the field.
+ * @type: type of the object.
+ * @member: name of the field within the object.
+ */
+#define container_of(ptr, type, member) \
+       ((type *) ((char *)(ptr) - offsetof(type, member)))
+
 #endif