]> git.draconx.ca Git - upkg.git/commitdiff
Implement GUID handling.
authorNick Bowler <nbowler@draconx.ca>
Mon, 8 Jun 2009 20:41:46 +0000 (16:41 -0400)
committerNick Bowler <nbowler@draconx.ca>
Tue, 9 Jun 2009 02:42:02 +0000 (22:42 -0400)
src/libupkg.c
src/upkg.c
src/upkg.h

index f7c55ba2fbf26428c110369e021d7c4d0bb6484e..f2addc9447a4ea6105f55572644d3904adf899a1 100644 (file)
@@ -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;
        }
index 02d8e5737e1a2c2ceab18c9d12425341b3cb940c..20b7336155a1077840d171889aff71b859e68e6d 100644 (file)
@@ -37,6 +37,16 @@ void print_upkg_flags(const char *prefix, unsigned long flags)
                printf("%sRequired\n", prefix);
 }
 
+void print_guid(unsigned char guid[static 16])
+{
+       for (unsigned i = 0; i < 16; i++) {
+               printf("%02hhx", guid[i]);
+               if (i == 15)
+                       putchar('\n');
+               else
+                       putchar(' ');
+       }
+}
 
 int main(int argc, char **argv)
 {
@@ -55,6 +65,8 @@ int main(int argc, char **argv)
 
        printf("Version: %u\n",  pkg->version);
        printf("License: %u\n",  pkg->license);
+       printf("GUID: ");
+       print_guid(pkg->guid);
 
        printf("Flags:   %lx\n", pkg->flags);
        print_upkg_flags("\t", pkg->flags);
index 8aa81a11af838140f7f1a90feeb5a989008ee28d..2e92e8527c1570e78be20bb8fa14792041a5b39f 100644 (file)
@@ -44,6 +44,7 @@
 
 struct upkg {
        unsigned version, license;
+       unsigned char guid[16];
        unsigned long flags;
 
        unsigned long name_count, export_count, import_count;