tdb2: unify tdb1_traverse into tdb_traverse
[ccan] / ccan / tdb / io.c
index e56be6fa38362e9b8666f34deb43c38b80831a13..2262eabf93b19daf524b3876d8b7f55c1fe882ea 100644 (file)
@@ -125,9 +125,17 @@ static int tdb_write(struct tdb_context *tdb, tdb_off_t off,
 /* Endian conversion: we only ever deal with 4 byte quantities */
 void *tdb_convert(void *buf, uint32_t size)
 {
-       uint32_t i, *p = (uint32_t *)buf;
-       for (i = 0; i < size / 4; i++)
-               p[i] = TDB_BYTEREV(p[i]);
+       uint32_t i;
+       unsigned char *p = buf, tmp;
+
+       for (i = 0; i < size; i += 4) {
+               tmp = p[i];
+               p[i] = p[i+3];
+               p[i+3] = tmp;
+               tmp = p[i+1];
+               p[i+1] = p[i+2];
+               p[i+2] = tmp;
+       }
        return buf;
 }