]> git.draconx.ca Git - upkg.git/blobdiff - src/libupkg.c
upkg: Add support for listing package imports.
[upkg.git] / src / libupkg.c
index acbf80f49c00bbf46cd9ae970ce8aef2c08ada29..f1424e8977048e70e19cdb44dac42036207d874a 100644 (file)
@@ -271,7 +271,6 @@ static int pkg_init_exports(struct upkg_priv *pkg)
 
        while (index < pkg->pub.export_count) {
                struct upkg_export_priv *export = &pkg->exports[index];
-               unsigned long parent_index;
                long tmp;
 
                /* Read some data into buffer. */
@@ -292,15 +291,17 @@ static int pkg_init_exports(struct upkg_priv *pkg)
                len += rc;
 
                if (nbuf-len < 4) goto err;
-               parent_index = unpack_32_le(buf+len);
+               tmp = unpack_s32_le(buf+len);
+               if (tmp < 0)
+                       goto err;
                len += 4;
 
                export->pub.parent = NULL;
-               if (parent_index > 0) {
-                       parent_index--;
-                       if (parent_index >= pkg->pub.export_count)
+               if (tmp > 0) {
+                       tmp--;
+                       if (tmp >= pkg->pub.export_count)
                                goto err;
-                       export->pub.parent = &pkg->exports[parent_index].pub;
+                       export->pub.parent = &pkg->exports[tmp].pub;
                }
 
                rc = upkg_decode_index(&tmp, buf+len, nbuf-len);
@@ -532,6 +533,15 @@ const struct upkg_export *upkg_get_export(struct upkg *pub, unsigned long idx)
        return NULL;
 }
 
+const struct upkg_import *upkg_get_import(struct upkg *pub, unsigned long idx)
+{
+       struct upkg_priv *pkg = (struct upkg_priv *)pub;
+
+       if (idx < pkg->pub.import_count)
+               return &pkg->imports[idx];
+       return NULL;
+}
+
 const char *upkg_export_class(struct upkg *pub, unsigned long idx,
                               const char **package)
 {