X-Git-Url: https://git.draconx.ca/gitweb/upkg.git/blobdiff_plain/3dd8f219561d68c12b04ef2d226a23e495b7c540..67988e9de2e9002064d52b4a1c5b5c4f8e6e665f:/src/libupkg.c diff --git a/src/libupkg.c b/src/libupkg.c index f7c55ba..f2addc9 100644 --- a/src/libupkg.c +++ b/src/libupkg.c @@ -124,6 +124,34 @@ static struct upkg *init_upkg(unsigned char hdr[static UPKG_HDR_SIZE]) return &alloc->pkg; } +static int pkg_init_guid(struct upkg *pkg) +{ + size_t rc; + + if (pkg->version < 68) { + unsigned long heritage_count, heritage_offset; + unsigned char buf[8]; + + rc = fread(buf, 1, sizeof buf, pkg->priv->f); + if (rc < 8) + return -1; + + heritage_count = unpack_32_le(buf+0); + heritage_offset = unpack_32_le(buf+4); + + if (heritage_count == 0) + return -1; + if (fseek(pkg->priv->f, heritage_offset, SEEK_SET) != 0) + return -1; + } + + rc = fread(pkg->guid, 1, 16, pkg->priv->f); + if (rc < 16) + return -1; + + return 0; +} + static int pkg_init_names(struct upkg *pkg) { size_t rc, len, nbuf = 0; @@ -335,6 +363,10 @@ struct upkg *upkg_fopen(const char *path) } pkg->priv->f = f; + if (pkg_init_guid(pkg) != 0) { + goto err2; + } + if (pkg_init_names(pkg) != 0) { goto err2; }