15 struct upkg_table names, exports, imports;
16 unsigned char guid[16];
19 static struct upkg *init_upkg(unsigned char hdr[static UPKG_HDR_SIZE])
23 pkg = malloc(sizeof *pkg);
28 pkg->priv = malloc(sizeof *pkg->priv);
34 pkg->version = unpack_16_le(hdr+4);
35 pkg->license = unpack_16_le(hdr+6);
36 pkg->flags = unpack_32_le(hdr+8);
38 pkg->priv->names = (struct upkg_table) {
39 .count = unpack_32_le(hdr+12),
40 .offset = unpack_32_le(hdr+16),
42 pkg->priv->exports = (struct upkg_table) {
43 .count = unpack_32_le(hdr+20),
44 .offset = unpack_32_le(hdr+24),
46 pkg->priv->imports = (struct upkg_table) {
47 .count = unpack_32_le(hdr+28),
48 .offset = unpack_32_le(hdr+32),
54 struct upkg *upkg_fopen(const char *path)
56 unsigned char hdr_buf[UPKG_HDR_SIZE];
60 f = fopen(path, "rb");
65 if (fread(hdr_buf, sizeof hdr_buf, 1, f) != 1) {
69 if (unpack_32_le(hdr_buf) != UPKG_HDR_MAGIC) {
73 pkg = init_upkg(hdr_buf);