summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile1
-rw-r--r--src/struct_offsets.c23
2 files changed, 24 insertions, 0 deletions
diff --git a/src/Makefile b/src/Makefile
index 37ae219..b6d0499 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -55,6 +55,7 @@ libaio.a: $(libaio_objs)
$(RANLIB) libaio.a
$(libname): $(libaio_sobjs) libaio.map
+ $(CC) $(CFLAGS) -c struct_offsets.c
$(CC) $(SO_CFLAGS) -Wl,--version-script=libaio.map -Wl,-soname=$(soname) -o $@ $(libaio_sobjs) $(LINK_FLAGS)
install: $(all_targets)
diff --git a/src/struct_offsets.c b/src/struct_offsets.c
new file mode 100644
index 0000000..4dc6fcc
--- /dev/null
+++ b/src/struct_offsets.c
@@ -0,0 +1,23 @@
+/*
+ * Ensure that data structure offsets in the iocb.u union match.
+ * Note that this code does not end up in the compiled object files.
+ * Its sole purpose is to abort the build if the structure padding
+ * is incorrect.
+ */
+#include <stddef.h>
+#include <assert.h>
+#include <libaio.h>
+
+void
+offset_check(void)
+{
+ static_assert(offsetof(struct iocb, u.v.nr) ==
+ offsetof(struct iocb, u.c.nbytes),
+ "Error: iocb.u.v.nr does not match the offset of iocb.u.c.nbytes.");
+ static_assert(offsetof(struct iocb, u.v.offset) ==
+ offsetof(struct iocb, u.c.offset),
+ "Error: iocb.u.v.offset does not match the offset of iocb.u.c.offset");
+ static_assert(offsetof(struct iocb, u.saddr.len) ==
+ offsetof(struct iocb, u.c.nbytes),
+ "Error: iocb.u.saddr.len does not match the offset of iocb.u.c.nbytes");
+}