]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-compat-util.h
introduce container_of macro
[thirdparty/git.git] / git-compat-util.h
index 83be89de0aac7c96799635e3b2858a465f440acf..4cc2c8283ac91d75bc23096b9f3cdfc00c391743 100644 (file)
@@ -1312,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