avoid magic numbers when writing pack index header in got-index-pack
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
diff --git a/libexec/got-index-pack/got-index-pack.c b/libexec/got-index-pack/got-index-pack.c
index 05e55c2..6d6289b 100644
--- a/libexec/got-index-pack/got-index-pack.c
+++ b/libexec/got-index-pack/got-index-pack.c
@@ -89,25 +89,14 @@ struct got_indexed_object {
} delta;
};
-#define PUTBE32(b, n)\
- do{ \
- (b)[0] = (n) >> 24; \
- (b)[1] = (n) >> 16; \
- (b)[2] = (n) >> 8; \
- (b)[3] = (n) >> 0; \
- } while(0)
-
-#define PUTBE64(b, n)\
- do{ \
- (b)[0] = (n) >> 56; \
- (b)[1] = (n) >> 48; \
- (b)[2] = (n) >> 40; \
- (b)[3] = (n) >> 32; \
- (b)[4] = (n) >> 24; \
- (b)[5] = (n) >> 16; \
- (b)[6] = (n) >> 8; \
- (b)[7] = (n) >> 0; \
- } while(0)
+static void
+putbe32(char *b, uint32_t n)
+{
+ b[0] = n >> 24;
+ b[1] = n >> 16;
+ b[2] = n >> 8;
+ b[3] = n >> 0;
+}
static const struct got_error *
get_obj_type_label(const char **label, int obj_type)
@@ -747,7 +736,9 @@ index_pack(struct got_pack *pack, int idxfd, uint8_t *pack_hash,
make_packidx(&packidx, nobj, objects);
SHA1Init(&ctx);
- err = hwrite(idxfd, "\xfftOc\x00\x00\x00\x02", 8, &ctx);
+ putbe32(buf, GOT_PACKIDX_V2_MAGIC);
+ putbe32(buf + 4, GOT_PACKIDX_VERSION);
+ err = hwrite(idxfd, buf, 8, &ctx);
if (err)
goto done;
err = hwrite(idxfd, packidx.hdr.fanout_table,
@@ -759,7 +750,7 @@ index_pack(struct got_pack *pack, int idxfd, uint8_t *pack_hash,
if (err)
goto done;
for(i = 0; i < nobj; i++){
- PUTBE32(buf, objects[i].crc);
+ putbe32(buf, objects[i].crc);
err = hwrite(idxfd, buf, 4, &ctx);
if (err)
goto done;