util: add virendian.h macros

We have several cases where we need to read endian-dependent
data regardless of host endianness; rather than open-coding
these call sites, it will be nicer to funnel things through
a macro.

The virendian.h file can be expanded to add writer functions,
and/or 16-bit access patterns, if needed.  Also, if we need
to turn things into a function to avoid multiple evaluations
of buf, that can be done later.  But for now, a macro worked.

* src/util/virendian.h: New file.
* src/Makefile.am (UTIL_SOURCES): Ship it.
* tests/virendiantest.c: New test.
* tests/Makefile.am (test_programs, virendiantest_SOURCES): Run
the test.
* .gitignore: Ignore built file.
This commit is contained in:
Eric Blake committed 2013-02-12 09:00:15 -07:00
1 parent d1c7b00b60
commit c6f1060ca7
5 files changed
+203 -2

No files matched your search

+1
View File
@@ -177,6 +177,7 @@
/tests/virbitmaptest
/tests/virbuftest
/tests/virdrivermoduletest
/tests/virendiantest
/tests/virhashtest
/tests/virkeyfiletest
/tests/virlockspacetest