summaryrefslogtreecommitdiff
path: root/src/package.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-07-14 13:27:21 +0300
committerTimo Teras <timo.teras@iki.fi>2009-07-14 13:27:21 +0300
commit8d1eeb58e450ef4a81497c3233a929350af3e467 (patch)
treed2dcec64c9449ea431fb259410e1136479e21bc8 /src/package.c
parentab37bd0b0c0da340222f8420ec2ee6ccdd13ce24 (diff)
downloadapk-tools-8d1eeb58e450ef4a81497c3233a929350af3e467.tar.gz
apk-tools-8d1eeb58e450ef4a81497c3233a929350af3e467.tar.bz2
apk-tools-8d1eeb58e450ef4a81497c3233a929350af3e467.tar.xz
apk-tools-8d1eeb58e450ef4a81497c3233a929350af3e467.zip
blob: some helpers to replace snprintf
snprintf is dog slow. make the blob stuff have some helper functions so we can use them in code paths that are executed often.
Diffstat (limited to 'src/package.c')
-rw-r--r--src/package.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/package.c b/src/package.c
index 1b72f1c..c6c6737 100644
--- a/src/package.c
+++ b/src/package.c
@@ -290,17 +290,19 @@ int apk_pkg_add_info(struct apk_database *db, struct apk_package *pkg,
apk_deps_parse(db, &pkg->depends, value);
break;
case 'C':
- apk_hexdump_parse(APK_BLOB_BUF(pkg->csum), value);
+ apk_blob_pull_hexdump(&value, APK_BLOB_BUF(pkg->csum));
break;
case 'S':
- pkg->size = apk_blob_parse_uint(&value, 10);
+ pkg->size = apk_blob_pull_uint(&value, 10);
break;
case 'I':
- pkg->installed_size = apk_blob_parse_uint(&value, 10);
+ pkg->installed_size = apk_blob_pull_uint(&value, 10);
break;
default:
return -1;
}
+ if (APK_BLOB_IS_NULL(value))
+ return -1;
return 0;
}
@@ -643,22 +645,29 @@ int apk_pkg_write_index_entry(struct apk_package *info,
struct apk_ostream *os)
{
char buf[512];
- int n, r, t = 0;
-
- n = snprintf(buf, sizeof(buf),
- "P:%s\n"
- "V:%s\n"
- "S:%zu\n"
- "I:%zu\n"
- "T:%s\n"
- "U:%s\n"
- "L:%s\n",
- info->name->name, info->version,
- info->size, info->installed_size,
- info->description, info->url, info->license);
- if (os->write(os, buf, n) != n)
+ apk_blob_t bbuf = APK_BLOB_BUF(buf);
+ int r;
+
+ apk_blob_push_blob(&bbuf, APK_BLOB_STR("C:"));
+ apk_blob_push_hexdump(&bbuf, APK_BLOB_BUF(info->csum));
+ apk_blob_push_blob(&bbuf, APK_BLOB_STR("\nP:"));
+ apk_blob_push_blob(&bbuf, APK_BLOB_STR(info->name->name));
+ apk_blob_push_blob(&bbuf, APK_BLOB_STR("\nV:"));
+ apk_blob_push_blob(&bbuf, APK_BLOB_STR(info->version));
+ apk_blob_push_blob(&bbuf, APK_BLOB_STR("\nS:"));
+ apk_blob_push_uint(&bbuf, info->size, 10);
+ apk_blob_push_blob(&bbuf, APK_BLOB_STR("\nI:"));
+ apk_blob_push_uint(&bbuf, info->installed_size, 10);
+ apk_blob_push_blob(&bbuf, APK_BLOB_STR("\nT:"));
+ apk_blob_push_blob(&bbuf, APK_BLOB_STR(info->description));
+ apk_blob_push_blob(&bbuf, APK_BLOB_STR("\nU:"));
+ apk_blob_push_blob(&bbuf, APK_BLOB_STR(info->url));
+ apk_blob_push_blob(&bbuf, APK_BLOB_STR("\nL:"));
+ apk_blob_push_blob(&bbuf, APK_BLOB_STR(info->license));
+ apk_blob_push_blob(&bbuf, APK_BLOB_STR("\n"));
+
+ if (os->write(os, buf, bbuf.ptr - buf) != bbuf.ptr - buf)
return -1;
- t += n;
if (info->depends != NULL) {
if (os->write(os, "D:", 2) != 2)
@@ -668,18 +677,9 @@ int apk_pkg_write_index_entry(struct apk_package *info,
return r;
if (os->write(os, "\n", 1) != 1)
return -1;
- t += r + 3;
}
- n = snprintf(buf, sizeof(buf), "C:");
- n += apk_hexdump_format(sizeof(buf)-n, &buf[n], APK_BLOB_BUF(info->csum));
- n += snprintf(&buf[n], sizeof(buf)-n, "\n");
-
- if (os->write(os, buf, n) != n)
- return -1;
- t += n;
-
- return n;
+ return 0;
}
int apk_pkg_version_compare(struct apk_package *a, struct apk_package *b)