diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2008-04-09 11:16:24 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2008-04-09 11:18:57 +0300 |
commit | 994ccffd9dee5d25da4fe4be1fa4d4b9baeea990 (patch) | |
tree | cc6dcf825c879909837f5b4d7771ab60bd922505 /rpmdb | |
parent | 7a64fb564a7c79e47a3ad86d17b5c671a64e44c4 (diff) | |
download | librpm-tizen-994ccffd9dee5d25da4fe4be1fa4d4b9baeea990.tar.gz librpm-tizen-994ccffd9dee5d25da4fe4be1fa4d4b9baeea990.tar.bz2 librpm-tizen-994ccffd9dee5d25da4fe4be1fa4d4b9baeea990.zip |
Rewrite headerGetN*() for simplicity
- eliminate stpcpy() games
- reuse evr formatting from headerGetEVR() instead of doing it over and
over again everywhere
Diffstat (limited to 'rpmdb')
-rw-r--r-- | rpmdb/hdrNVR.c | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/rpmdb/hdrNVR.c b/rpmdb/hdrNVR.c index b329de18b..a7f36a301 100644 --- a/rpmdb/hdrNVR.c +++ b/rpmdb/hdrNVR.c @@ -56,40 +56,35 @@ int headerNEVRA(Header h, const char **np, char * headerGetNEVR(Header h, const char ** np) { - const char * n, * v, * r; - char * NVR, * t; - - (void) headerNVR(h, &n, &v, &r); - NVR = t = xcalloc(1, strlen(n) + strlen(v) + strlen(r) + sizeof("--")); - t = stpcpy(t, n); - t = stpcpy(t, "-"); - t = stpcpy(t, v); - t = stpcpy(t, "-"); - t = stpcpy(t, r); + const char * n; + char * evr, *nevr = NULL; + + evr = headerGetEVR(h, &n); + rasprintf(&nevr, "%s-%s", n, evr); + free(evr); if (np) *np = n; - return NVR; + return nevr; } char * headerGetNEVRA(Header h, const char ** np) { - const char * n, * v, * r, * a; - char * NVRA, * t; - int xx; - - (void) headerNVR(h, &n, &v, &r); - xx = headerGetEntry(h, RPMTAG_ARCH, NULL, (rpm_data_t *) &a, NULL); - NVRA = t = xcalloc(1, strlen(n) + strlen(v) + strlen(r) + strlen(a) + sizeof("--.")); - t = stpcpy(t, n); - t = stpcpy(t, "-"); - t = stpcpy(t, v); - t = stpcpy(t, "-"); - t = stpcpy(t, r); - t = stpcpy(t, "."); - t = stpcpy(t, a); + const char *n, *a; + char *nevr, *nevra = NULL; + + nevr = headerGetNEVR(h, &n); + headerGetEntry(h, RPMTAG_ARCH, NULL, (rpm_data_t *) &a, NULL); + /* XXX gpg-pubkey packages have no arch, urgh... */ + if (a) { + rasprintf(&nevra, "%s.%s", nevr, a); + free(nevr); + } else { + nevra = nevr; + } + if (np) *np = n; - return NVRA; + return nevra; } char * headerGetEVR(Header h, const char ** np) |