1 /* Reduced from git-2.39.0's pack-revindex.c */
3 typedef unsigned int __uint32_t
;
4 typedef unsigned long int __uintmax_t
;
5 typedef long int __off_t
;
6 typedef long int __off64_t
;
7 typedef __SIZE_TYPE__
size_t;
8 typedef __off64_t off_t
;
9 typedef __uint32_t
uint32_t;
10 typedef __uintmax_t
uintmax_t;
18 extern int close(int __fd
);
19 extern int fstat(int __fd
, struct stat
*__buf
)
20 __attribute__((__nothrow__
, __leaf__
)) __attribute__((__nonnull__(2)));
21 extern uint32_t default_swab32(uint32_t val
);
22 extern uint32_t git_bswap32(uint32_t x
);
23 __attribute__((__noreturn__
)) void die(const char *err
, ...)
24 __attribute__((format(printf
, 1, 2)));
25 int error(const char *err
, ...) __attribute__((format(printf
, 1, 2)));
26 int error_errno(const char *err
, ...) __attribute__((format(printf
, 1, 2)));
27 static inline int const_error(void) { return -1; }
28 extern int munmap(void *__addr
, size_t __len
)
29 __attribute__((__nothrow__
, __leaf__
));
30 extern size_t st_mult(size_t a
, size_t b
);
31 extern void *xmmap(void *start
, size_t length
, int prot
, int flags
, int fd
,
33 extern size_t xsize_t(off_t len
);
35 extern char *gettext(const char *__msgid
) __attribute__((__nothrow__
, __leaf__
))
36 __attribute__((__format_arg__(1)));
37 static inline __attribute__((format_arg(1))) const char *_(const char *msgid
) {
40 return gettext(msgid
);
45 const struct git_hash_algo
*hash_algo
;
48 extern struct repository
*the_repository
;
49 struct git_hash_algo
{
55 int git_open_cloexec(const char *name
, int flags
);
57 struct revindex_header
{
63 int load_revindex_from_disk(char *revindex_name
, uint32_t num_objects
,
64 const uint32_t **data_p
, size_t *len_p
) {
67 void *data
= ((void *)0);
69 struct revindex_header
*hdr
;
71 fd
= git_open_cloexec(revindex_name
, 00);
78 ret
= (error_errno(_("failed to read %s"), revindex_name
), const_error());
82 revindex_size
= xsize_t(st
.st_size
);
84 if (revindex_size
< ((12) + (2 * the_repository
->hash_algo
->rawsz
))) {
85 ret
= (error(_("reverse-index file %s is too small"), revindex_name
),
90 if (revindex_size
- ((12) + (2 * the_repository
->hash_algo
->rawsz
)) !=
91 st_mult(sizeof(uint32_t), num_objects
)) {
92 ret
= (error(_("reverse-index file %s is corrupt"), revindex_name
),
97 data
= xmmap(((void *)0), revindex_size
, 0x1, 0x02, fd
, 0);
98 hdr
= (struct revindex_header
*) data
;
100 if (git_bswap32(hdr
->signature
) != 0x52494458) {
102 (error(_("reverse-index file %s has unknown signature"), revindex_name
),
106 if (git_bswap32(hdr
->version
) != 1) {
107 ret
= (error(_("reverse-index file %s has unsupported version %"
109 revindex_name
, git_bswap32(hdr
->version
)),
113 if (!(git_bswap32(hdr
->hash_id
) == 1 || git_bswap32(hdr
->hash_id
) == 2)) {
114 ret
= (error(_("reverse-index file %s has unsupported hash id %"
116 revindex_name
, git_bswap32(hdr
->hash_id
)),
123 if (data
) /* { dg-bogus "check of 'data' for NULL after already dereferencing it" } */
124 munmap(data
, revindex_size
);
126 *len_p
= revindex_size
;
127 *data_p
= (const uint32_t *)data
;