summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2011-08-16 19:03:26 -0400
committerMatt Turner <mattst88@gmail.com>2011-09-21 17:14:44 -0400
commit893e86a49e3e381cff48a9e86dc2d9b3d5431d95 (patch)
tree38719d11dbfe60cd73899f1c7a394c8b7c23887f
parent54770c980cd2b91a8377f975a58ed69def5cfa42 (diff)
Introduce swap_uint{16,32} functions, used in swap{l,s}
Reviewed-by: Peter Harris <pharris@opentext.com> Signed-off-by: Matt Turner <mattst88@gmail.com>
-rw-r--r--include/misc.h30
1 files changed, 20 insertions, 10 deletions
diff --git a/include/misc.h b/include/misc.h
index cca30d2d0..99046ae76 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -256,20 +256,30 @@ version_compare(uint16_t a_major, uint16_t a_minor,
SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff))
/* byte swap a 32-bit value */
+static inline void swap_uint32(uint32_t *x)
+{
+ char n = ((char *) &x)[0];
+ ((char *) x)[0] = ((char *) x)[3];
+ ((char *) x)[3] = n;
+ n = ((char *) x)[1];
+ ((char *) x)[1] = ((char *) x)[2];
+ ((char *) x)[2] = n;
+}
+
#define swapl(x) do { \
- char n = ((char *) (x))[0];\
- ((char *) (x))[0] = ((char *) (x))[3];\
- ((char *) (x))[3] = n;\
- n = ((char *) (x))[1];\
- ((char *) (x))[1] = ((char *) (x))[2];\
- ((char *) (x))[2] = n;\
+ swap_uint32((uint32_t *)(x)); \
} while (0)
-/* byte swap a short */
+/* byte swap a 16-bit value */
+static inline void swap_uint16(uint16_t *x)
+{
+ char n = ((char *) x)[0];
+ ((char *) x)[0] = ((char *) x)[1];
+ ((char *) x)[1] = n;
+}
+
#define swaps(x) do { \
- char n = ((char *) (x))[0];\
- ((char *) (x))[0] = ((char *) (x))[1];\
- ((char *) (x))[1] = n;\
+ swap_uint16((uint16_t *)(x)); \
} while (0)
/* copy 32-bit value from src to dst byteswapping on the way */