]> git.ozlabs.org Git - ccan/blobdiff - ccan/structeq/structeq.h
structeq: new module.
[ccan] / ccan / structeq / structeq.h
diff --git a/ccan/structeq/structeq.h b/ccan/structeq/structeq.h
new file mode 100644 (file)
index 0000000..3af20c5
--- /dev/null
@@ -0,0 +1,17 @@
+/* CC0 (Public domain) - see LICENSE file for details */
+#ifndef CCAN_STRUCTEQ_H
+#define CCAN_STRUCTEQ_H
+#include <string.h>
+
+/**
+ * structeq - are two structures bitwise equal (including padding!)
+ * @a: a pointer to a structure
+ * @b: a pointer to a structure of the same type.
+ *
+ * If you *know* a structure has no padding, you can memcmp them.  At
+ * least this way, the compiler will issue a warning if the structs are
+ * different types!
+ */
+#define structeq(a, b) \
+       (memcmp((a), (b), sizeof(*(a)) + 0 * sizeof((a) == (b))) == 0)
+#endif /* CCAN_STRUCTEQ_H */