commit - 81a12da58651e79380d81dea7020bf6af20bb28b
commit + 78fb09675bee22e8ae24eb8bd9a86d8a04b17a7e
blob - 86971081d57bb312c6571c4a5ae79e576a5643aa
blob + 057287fe2e3af2b2946dd2b22aa97981474ed83a
--- lib/fetch.c
+++ lib/fetch.c
#include <sys/resource.h>
#include <sys/socket.h>
+#include <endian.h>
#include <errno.h>
#include <err.h>
#include <fcntl.h>
"bad pack file version");
goto done;
}
- nobj = betoh32(pack_hdr.nobjects);
+ nobj = be32toh(pack_hdr.nobjects);
if (nobj == 0 &&
packfile_size > sizeof(pack_hdr) + SHA1_DIGEST_LENGTH)
return got_error_msg(GOT_ERR_BAD_PACKFILE,
blob - 6a48cf6389fbe45e5c317c0e02cd53a91867cd4c
blob + ad61697895ee0d4066a8f7b1036fc1e0ac5fd005
--- lib/pack.c
+++ lib/pack.c
goto done;
}
}
- if (betoh32(*h->magic) != GOT_PACKIDX_V2_MAGIC) {
+ if (be32toh(*h->magic) != GOT_PACKIDX_V2_MAGIC) {
err = got_error(GOT_ERR_BAD_PACKIDX);
goto done;
}
goto done;
}
}
- if (betoh32(*h->version) != GOT_PACKIDX_VERSION) {
+ if (be32toh(*h->version) != GOT_PACKIDX_VERSION) {
err = got_error(GOT_ERR_BAD_PACKIDX);
goto done;
}
offset += len_fanout;
remain -= len_fanout;
- nobj = betoh32(h->fanout_table[0xff]);
+ nobj = be32toh(h->fanout_table[0xff]);
len_ids = nobj * sizeof(*h->sorted_ids);
if (len_ids <= nobj || len_ids > remain) {
err = got_error(GOT_ERR_BAD_PACKIDX);
/* Large file offsets are contained only in files > 2GB. */
for (i = 0; i < nobj; i++) {
- uint32_t o = betoh32(h->offsets[i]);
+ uint32_t o = be32toh(h->offsets[i]);
if (o & GOT_PACKIDX_OFFSET_VAL_IS_LARGE_IDX)
p->nlargeobj++;
}
static off_t
get_object_offset(struct got_packidx *packidx, int idx)
{
- uint32_t offset = betoh32(packidx->hdr.offsets[idx]);
+ uint32_t offset = be32toh(packidx->hdr.offsets[idx]);
if (offset & GOT_PACKIDX_OFFSET_VAL_IS_LARGE_IDX) {
uint64_t loffset;
idx = offset & GOT_PACKIDX_OFFSET_VAL_MASK;
if (idx < 0 || idx >= packidx->nlargeobj ||
packidx->hdr.large_offsets == NULL)
return -1;
- loffset = betoh64(packidx->hdr.large_offsets[idx]);
+ loffset = be64toh(packidx->hdr.large_offsets[idx]);
return (loffset > INT64_MAX ? -1 : (off_t)loffset);
}
return (off_t)(offset & GOT_PACKIDX_OFFSET_VAL_MASK);
got_packidx_get_object_idx(struct got_packidx *packidx, struct got_object_id *id)
{
u_int8_t id0 = id->sha1[0];
- uint32_t totobj = betoh32(packidx->hdr.fanout_table[0xff]);
+ uint32_t totobj = be32toh(packidx->hdr.fanout_table[0xff]);
int left = 0, right = totobj - 1;
if (id0 > 0)
- left = betoh32(packidx->hdr.fanout_table[id0 - 1]);
+ left = be32toh(packidx->hdr.fanout_table[id0 - 1]);
while (left <= right) {
struct got_packidx_object_id *oid;
{
const struct got_error *err = NULL;
u_int8_t id0;
- uint32_t totobj = betoh32(packidx->hdr.fanout_table[0xff]);
+ uint32_t totobj = be32toh(packidx->hdr.fanout_table[0xff]);
char hex[3];
size_t prefix_len = strlen(id_str_prefix);
struct got_packidx_object_id *oid;
if (!got_parse_xdigit(&id0, hex))
return got_error_path(id_str_prefix, GOT_ERR_BAD_OBJ_ID_STR);
- i = betoh32(packidx->hdr.fanout_table[id0 - 1]);
+ i = be32toh(packidx->hdr.fanout_table[id0 - 1]);
if (i == 0)
return NULL;
blob - 8860e1831b9a9021198957db53b2d3632a242df4
blob + c2ee66c55abf30b586e88619a4a81d4be0c443bf
--- lib/repository.c
+++ lib/repository.c
#include <sys/syslimits.h>
#include <ctype.h>
+#include <endian.h>
#include <fcntl.h>
#include <fnmatch.h>
#include <limits.h>
read_packfile_hdr(int fd, struct got_packidx *packidx)
{
const struct got_error *err = NULL;
- uint32_t totobj = betoh32(packidx->hdr.fanout_table[0xff]);
+ uint32_t totobj = be32toh(packidx->hdr.fanout_table[0xff]);
struct got_packfile_hdr hdr;
ssize_t n;
if (n != sizeof(hdr))
return got_error(GOT_ERR_BAD_PACKFILE);
- if (betoh32(hdr.signature) != GOT_PACKFILE_SIGNATURE ||
- betoh32(hdr.version) != GOT_PACKFILE_VERSION ||
- betoh32(hdr.nobjects) != totobj)
+ if (be32toh(hdr.signature) != GOT_PACKFILE_SIGNATURE ||
+ be32toh(hdr.version) != GOT_PACKFILE_VERSION ||
+ be32toh(hdr.nobjects) != totobj)
err = got_error(GOT_ERR_BAD_PACKFILE);
return err;
blob - 10955c887d40ead647e9bdb923b82fcc3bce37d4
blob + 60075c04efe69ab4514e49c8ffd6bf8c390eb6e0
--- libexec/got-index-pack/got-index-pack.c
+++ libexec/got-index-pack/got-index-pack.c
#include <string.h>
#include <ctype.h>
#include <sha1.h>
+#include <endian.h>
#include <fcntl.h>
#include <unistd.h>
#include <zlib.h>
find_object_idx(struct got_packidx *packidx, uint8_t *sha1)
{
u_int8_t id0 = sha1[0];
- uint32_t nindexed = betoh32(packidx->hdr.fanout_table[0xff]);
+ uint32_t nindexed = be32toh(packidx->hdr.fanout_table[0xff]);
int left = 0, right = nindexed - 1;
int cmp = 0, i = 0;
if (id0 > 0)
- left = betoh32(packidx->hdr.fanout_table[id0 - 1]);
+ left = be32toh(packidx->hdr.fanout_table[id0 - 1]);
while (left <= right) {
struct got_packidx_object_id *oid;
static void
print_packidx(struct got_packidx *packidx)
{
- uint32_t nindexed = betoh32(packidx->hdr.fanout_table[0xff]);
+ uint32_t nindexed = be32toh(packidx->hdr.fanout_table[0xff]);
int i;
fprintf(stderr, "object IDs:\n");
struct got_indexed_object *obj)
{
uint32_t idx;
- uint32_t nindexed = betoh32(packidx->hdr.fanout_table[0xff]);
+ uint32_t nindexed = be32toh(packidx->hdr.fanout_table[0xff]);
idx = find_object_idx(packidx, obj->id.sha1);
if (idx == -1) {
if (hdr.version != htobe32(GOT_PACKFILE_VERSION))
return got_error_msg(GOT_ERR_BAD_PACKFILE,
"bad packfile version");
- nobj = betoh32(hdr.nobjects);
+ nobj = be32toh(hdr.nobjects);
if (nobj == 0)
return got_error_msg(GOT_ERR_BAD_PACKFILE,
"bad packfile with zero objects");