summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libopkg/pkg.c43
-rw-r--r--libopkg/pkg_parse.c70
2 files changed, 44 insertions, 69 deletions
diff --git a/libopkg/pkg.c b/libopkg/pkg.c
index b1f45dd..bb3da1e 100644
--- a/libopkg/pkg.c
+++ b/libopkg/pkg.c
@@ -945,32 +945,27 @@ int abstract_pkg_name_compare(const void *p1, const void *p2)
}
-char *pkg_version_str_alloc(pkg_t *pkg)
+char *
+pkg_version_str_alloc(pkg_t *pkg)
{
- char *complete_version;
- char *epoch_str;
- char *revision_str;
-
- if (pkg->epoch) {
- sprintf_alloc(&epoch_str, "%d:", pkg->epoch);
- } else {
- epoch_str = xstrdup("");
- }
-
- if (pkg->revision && strlen(pkg->revision)) {
- sprintf_alloc(&revision_str, "-%s", pkg->revision);
- } else {
- revision_str = xstrdup("");
- }
-
-
- sprintf_alloc(&complete_version, "%s%s%s",
- epoch_str, pkg->version, revision_str);
-
- free(epoch_str);
- free(revision_str);
+ char *version;
+
+ if (pkg->epoch) {
+ if (pkg->revision)
+ sprintf_alloc(&version, "%d:%s-%s",
+ pkg->epoch, pkg->version, pkg->revision);
+ else
+ sprintf_alloc(&version, "%d:%s",
+ pkg->epoch, pkg->version);
+ } else {
+ if (pkg->revision)
+ sprintf_alloc(&version, "%s-%s",
+ pkg->version, pkg->revision);
+ else
+ version = xstrdup(pkg->version);
+ }
- return complete_version;
+ return version;
}
str_list_t *pkg_get_installed_files(pkg_t *pkg)
diff --git a/libopkg/pkg_parse.c b/libopkg/pkg_parse.c
index 44338f0..a8aa231 100644
--- a/libopkg/pkg_parse.c
+++ b/libopkg/pkg_parse.c
@@ -103,57 +103,37 @@ static void parseConffiles(pkg_t * pkg, const char * raw)
}
}
-int parseVersion(pkg_t *pkg, const char *raw)
+int
+parseVersion(pkg_t *pkg, const char *vstr)
{
- char *colon, *eepochcolon;
- char *hyphen;
- unsigned long epoch;
-
- if (!*raw) {
- fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
- return EINVAL;
- }
-
- if (strncmp(raw, "Version:", 8) == 0) {
- raw += 8;
- }
- while (*raw && isspace(*raw)) {
- raw++;
- }
-
- colon= strchr(raw,':');
- if (colon) {
- epoch= strtoul(raw,&eepochcolon,10);
- if (colon != eepochcolon) {
- fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
- return EINVAL;
- }
- if (!*++colon) {
- fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
- return EINVAL;
- }
- raw= colon;
- pkg->epoch= epoch;
- } else {
- pkg->epoch= 0;
- }
+ char *colon;
- pkg->revision = "";
+ if (strncmp(vstr, "Version:", 8) == 0)
+ vstr += 8;
- if (!pkg->version)
- {
- pkg->version= xcalloc(1, strlen(raw)+1);
- strcpy(pkg->version, raw);
- }
+ while (*vstr && isspace(*vstr))
+ vstr++;
- hyphen= strrchr(pkg->version,'-');
+ colon = strchr(vstr, ':');
+ if (colon) {
+ errno = 0;
+ pkg->epoch = strtoul(vstr, NULL, 10);
+ if (errno) {
+ fprintf(stderr, "%s: %s: invalid epoch: %s\n",
+ __FUNCTION__, pkg->name, strerror(errno));
+ }
+ vstr = ++colon;
+ } else {
+ pkg->epoch= 0;
+ }
+
+ pkg->version= xstrdup(vstr);
+ pkg->revision = strrchr(pkg->version,'-');
- if (hyphen) {
- *hyphen++= 0;
- pkg->revision = hyphen;
- }
+ if (pkg->revision)
+ *pkg->revision++ = '\0';
- return 0;
+ return 0;
}
static int