-/* key structure for the record routines */
-typedef struct {
- u_long number;
- u_long offset;
- u_long length;
-#define R_LENGTH 0x01 /* length is valid */
-#define R_NUMBER 0x02 /* record number is valid */
-#define R_OFFSET 0x04 /* offset is valid */
- u_char valid;
-} RECNOKEY;
-
-/* Little endian <--> big endian long swap macros. */
-#define BLSWAP(X) {(X) = __byte_swap_long(X);}
-#define BLSWAP_COPY(X,Y) {(Y) = __byte_swap_long(X);}
-
-/* Little endian <--> big endian short swap macros. */
-#define BSSWAP(X) {(X) = __byte_swap_word(X);}
-#define BSSWAP_COPY(X,Y) {(Y) = __byte_swap_word(X);}
+/*
+ * Little endian <==> big endian long swap macros.
+ * BLSWAP swap a memory location
+ * BLPSWAP swap a referenced memory location
+ * BLSWAP_COPY swap from one location to another
+ */
+#define BLSWAP(a) { \
+ u_long _tmp = a; \
+ ((char *)&a)[0] = ((char *)&_tmp)[3]; \
+ ((char *)&a)[1] = ((char *)&_tmp)[2]; \
+ ((char *)&a)[2] = ((char *)&_tmp)[1]; \
+ ((char *)&a)[3] = ((char *)&_tmp)[0]; \
+}
+#define BLPSWAP(a) { \
+ u_long _tmp = *(u_long *)a; \
+ ((char *)a)[0] = ((char *)&_tmp)[3]; \
+ ((char *)a)[1] = ((char *)&_tmp)[2]; \
+ ((char *)a)[2] = ((char *)&_tmp)[1]; \
+ ((char *)a)[3] = ((char *)&_tmp)[0]; \
+}
+#define BLSWAP_COPY(a, b) { \
+ ((char *)&(b))[0] = ((char *)&(a))[3]; \
+ ((char *)&(b))[1] = ((char *)&(a))[2]; \
+ ((char *)&(b))[2] = ((char *)&(a))[1]; \
+ ((char *)&(b))[3] = ((char *)&(a))[0]; \
+}
+
+/*
+ * Little endian <==> big endian short swap macros.
+ * BSSWAP swap a memory location
+ * BSPSWAP swap a referenced memory location
+ * BSSWAP_COPY swap from one location to another
+ */
+#define BSSWAP(a) { \
+ u_short _tmp = a; \
+ ((char *)&a)[0] = ((char *)&_tmp)[1]; \
+ ((char *)&a)[1] = ((char *)&_tmp)[0]; \
+}
+#define BSPSWAP(a) { \
+ u_short _tmp = *(u_short *)a; \
+ ((char *)a)[0] = ((char *)&_tmp)[1]; \
+ ((char *)a)[1] = ((char *)&_tmp)[0]; \
+}
+#define BSSWAP_COPY(a, b) { \
+ ((char *)&(b))[0] = ((char *)&(a))[1]; \
+ ((char *)&(b))[1] = ((char *)&(a))[0]; \
+}