diff options
Diffstat (limited to 'src/struct_offsets.c')
-rw-r--r-- | src/struct_offsets.c | 23 |
1 files changed, 23 insertions, 0 deletions
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"); +} |