11 #if defined(__GNUC__) && (__GNUC__ < 3)
14 #define FLEX_ARRAY /* empty */
19 unsigned int hdr_signature
;
20 unsigned int hdr_version
;
21 unsigned int hdr_entries
;
30 struct cache_time ce_ctime
;
31 struct cache_time ce_mtime
;
38 unsigned char sha1
[20];
39 unsigned short ce_flags
;
40 char name
[FLEX_ARRAY
]; /* more */
43 #define CE_NAMEMASK (0x0fff)
45 #define offsetof(type, member) __builtin_offsetof (type, member)
46 #define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) & ~7)
47 #define ce_namelen(ce) (CE_NAMEMASK & ntohs((ce)->ce_flags))
48 #define ce_size(ce) cache_entry_size(ce_namelen(ce))
50 int main(int argc
, char *argv
[])
56 unsigned int active_nr
;
57 struct cache_header
*hdr
;
60 printf("usage: %s: <index-file>\n", argv
[0]);
64 fd
= open(argv
[1], O_RDONLY
);
70 err
= fstat(fd
, &buf
);
76 index
= mmap(NULL
, buf
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0);
77 if (index
== MAP_FAILED
) {
84 active_nr
= ntohl(hdr
->hdr_entries
);
85 printf("Number of entries: %d\n\n", active_nr
);
86 printf("SHA1 file name\n");
87 printf("---- ---------\n");
88 offset
= sizeof(*hdr
);
89 for (i
= 0; i
< active_nr
; i
++) {
90 struct cache_entry
*ce
;
92 ce
= (struct cache_entry
*) ((char *) index
+ offset
);
93 printf("%#x %s\n", ce
->sha1
, ce
->name
);
95 offset
= offset
+ ce_size(ce
);
98 munmap(index
, buf
.st_size
);