4 int main(int argc
, char **argv
)
9 static unsigned int top_index
[256];
11 if (fread(top_index
, 2 * 4, 1, stdin
) != 1)
12 die("unable to read header");
13 if (top_index
[0] == htonl(PACK_IDX_SIGNATURE
)) {
14 version
= ntohl(top_index
[1]);
15 if (version
< 2 || version
> 2)
16 die("unknown index version");
17 if (fread(top_index
, 256 * 4, 1, stdin
) != 1)
18 die("unable to read index");
21 if (fread(&top_index
[2], 254 * 4, 1, stdin
) != 1)
22 die("unable to read index");
25 for (i
= 0; i
< 256; i
++) {
26 unsigned n
= ntohl(top_index
[i
]);
28 die("corrupt index file");
32 for (i
= 0; i
< nr
; i
++) {
33 unsigned int offset
, entry
[6];
35 if (fread(entry
, 4 + 20, 1, stdin
) != 1)
36 die("unable to read entry %u/%u", i
, nr
);
37 offset
= ntohl(entry
[0]);
38 printf("%u %s\n", offset
, sha1_to_hex((void *)(entry
+1)));
41 unsigned off64_nr
= 0;
43 unsigned char sha1
[20];
46 } *entries
= xmalloc(nr
* sizeof(entries
[0]));
47 for (i
= 0; i
< nr
; i
++)
48 if (fread(entries
[i
].sha1
, 20, 1, stdin
) != 1)
49 die("unable to read sha1 %u/%u", i
, nr
);
50 for (i
= 0; i
< nr
; i
++)
51 if (fread(&entries
[i
].crc
, 4, 1, stdin
) != 1)
52 die("unable to read crc %u/%u", i
, nr
);
53 for (i
= 0; i
< nr
; i
++)
54 if (fread(&entries
[i
].off
, 4, 1, stdin
) != 1)
55 die("unable to read 32b offset %u/%u", i
, nr
);
56 for (i
= 0; i
< nr
; i
++) {
58 uint32_t off
= ntohl(entries
[i
].off
);
59 if (!(off
& 0x80000000)) {
63 if ((off
& 0x7fffffff) != off64_nr
)
64 die("inconsistent 64b offset index");
65 if (fread(off64
, 8, 1, stdin
) != 1)
66 die("unable to read 64b offset %u", off64_nr
);
67 offset
= (((uint64_t)ntohl(off64
[0])) << 32) |
71 printf("%llu %s (%08x)\n", (unsigned long long) offset
,
72 sha1_to_hex(entries
[i
].sha1
),
73 ntohl(entries
[i
].crc
));