summaryrefslogtreecommitdiff
path: root/src/package.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2008-11-27 20:25:01 +0200
committerTimo Teras <timo.teras@iki.fi>2008-11-27 20:25:01 +0200
commitf0609951b9fd2938c0f30853e0aa6b08b8698a88 (patch)
tree3b1f72cbaad90d715d60643c0fac98b7aaedd37e /src/package.c
parent1a7f3e3678844165d2660ebff09da26b9ba01576 (diff)
downloadapk-tools-f0609951b9fd2938c0f30853e0aa6b08b8698a88.tar.gz
apk-tools-f0609951b9fd2938c0f30853e0aa6b08b8698a88.tar.bz2
apk-tools-f0609951b9fd2938c0f30853e0aa6b08b8698a88.tar.xz
apk-tools-f0609951b9fd2938c0f30853e0aa6b08b8698a88.zip
hash, db: use apk_blob_t and list_*
Diffstat (limited to 'src/package.c')
-rw-r--r--src/package.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/package.c b/src/package.c
index 3430d19..27300c7 100644
--- a/src/package.c
+++ b/src/package.c
@@ -25,6 +25,17 @@
#include "apk_database.h"
#include "apk_state.h"
+static struct apk_package *apk_pkg_new(void)
+{
+ struct apk_package *pkg;
+
+ pkg = calloc(1, sizeof(struct apk_package));
+ if (pkg != NULL)
+ list_init(&pkg->installed_pkgs_list);
+
+ return pkg;
+}
+
int apk_pkg_parse_name(apk_blob_t apkname,
apk_blob_t *name,
apk_blob_t *version)
@@ -67,7 +78,6 @@ static void parse_depend(struct apk_database *db,
{
struct apk_dependency *dep;
struct apk_name *name;
- char *cname;
while (blob.len && blob.ptr[0] == ' ')
blob.ptr++, blob.len--;
@@ -78,10 +88,7 @@ static void parse_depend(struct apk_database *db,
if (blob.len == 0)
return;
- cname = apk_blob_cstr(blob);
- name = apk_db_get_name(db, cname);
- free(cname);
-
+ name = apk_db_get_name(db, blob);
dep = apk_dependency_array_add(depends);
*dep = (struct apk_dependency){
.prefer_upgrade = 0,
@@ -185,13 +192,9 @@ struct read_info_ctx {
static int add_info(struct apk_database *db, struct apk_package *pkg,
char field, apk_blob_t value)
{
- char *str;
-
switch (field) {
case 'P':
- str = apk_blob_cstr(value);
- pkg->name = apk_db_get_name(db, str);
- free(str);
+ pkg->name = apk_db_get_name(db, value);
break;
case 'V':
pkg->version = apk_blob_cstr(value);
@@ -272,7 +275,7 @@ static int read_info_entry(void *ctx, const struct apk_file_info *ae,
struct apk_package *pkg = ri->pkg;
const int bsize = 4 * 1024;
apk_blob_t name, version;
- char *slash, *str;
+ char *slash;
int i;
/* Meta info and scripts */
@@ -298,11 +301,8 @@ static int read_info_entry(void *ctx, const struct apk_file_info *ae,
&name, &version) < 0)
return -1;
- if (pkg->name == NULL) {
- str = apk_blob_cstr(name);
- pkg->name = apk_db_get_name(db, str);
- free(str);
- }
+ if (pkg->name == NULL)
+ pkg->name = apk_db_get_name(db, name);
if (pkg->version == NULL)
pkg->version = apk_blob_cstr(version);
@@ -332,7 +332,7 @@ struct apk_package *apk_pkg_read(struct apk_database *db, const char *file)
struct stat st;
int fd;
- ctx.pkg = calloc(1, sizeof(struct apk_package));
+ ctx.pkg = apk_pkg_new();
if (ctx.pkg == NULL)
return NULL;
@@ -367,7 +367,7 @@ struct apk_package *apk_pkg_read(struct apk_database *db, const char *file)
/* Add implicit busybox dependency if there is scripts */
if (ctx.has_install) {
struct apk_dependency dep = {
- .name = apk_db_get_name(db, "busybox"),
+ .name = apk_db_get_name(db, APK_BLOB_STR("busybox")),
};
apk_deps_add(&ctx.pkg->depends, &dep);
}
@@ -402,7 +402,7 @@ void apk_pkg_free(struct apk_package *pkg)
int apk_pkg_get_state(struct apk_package *pkg)
{
- if (hlist_hashed(&pkg->installed_pkgs_list))
+ if (list_hashed(&pkg->installed_pkgs_list))
return APK_STATE_INSTALL;
return APK_STATE_NO_INSTALL;
}
@@ -497,7 +497,7 @@ struct apk_package *apk_pkg_parse_index_entry(struct apk_database *db, apk_blob_
{
struct read_info_ctx ctx;
- ctx.pkg = calloc(1, sizeof(struct apk_package));
+ ctx.pkg = apk_pkg_new();
if (ctx.pkg == NULL)
return NULL;