diff --git a/include/xbps_api.h b/include/xbps_api.h index 3b21852e..bed244d5 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -1124,6 +1124,16 @@ char *xbps_get_pkg_name(const char *pkg); */ char *xbps_get_pkgpattern_name(const char *pattern); +/** + * Gets the package epoch version in a package string, i.e foo-2.0:epoch. + * + * @param[in] pkg Package string. + * + * @return A string with the epoch version string, NULL if it couldn't find + * the epoch component. + */ +const char *xbps_get_pkg_epoch(const char *pkg); + /** * Gets the package version in a package string, i.e foo-2.0. * diff --git a/lib/cmpver.c b/lib/cmpver.c index 5fd9ede9..08db6817 100644 --- a/lib/cmpver.c +++ b/lib/cmpver.c @@ -29,7 +29,7 @@ * split_version(pkgname, endname, epoch, revision) returns a pointer to * the version portion of a package name and the two special components. * - * Syntax is: ${PKGNAME}-${VERSION}[_${PKGREVISION}][-${EPOCH}] + * Syntax is: ${PKGNAME}-${VERSION}[_${PKGREVISION}][:${EPOCH}] * */ static const char * @@ -54,8 +54,8 @@ split_version(const char *pkgname, const char **endname, unsigned long *epoch, } endversionstr = ch; - /* Look for the last '-' in the remaining version string */ - ch = strrchr(endversionstr ? endversionstr + 1 : versionstr, '-'); + /* Look for the last ':' in the remaining version string */ + ch = strrchr(endversionstr ? endversionstr + 1 : versionstr, ':'); if (epoch != NULL) { *epoch = ch ? strtoul(ch + 1, NULL, 10) : 0; } @@ -216,7 +216,7 @@ get_component(const char *position, version_component *component) * comparison of the basenames is done. * * The port version is defined by: - * ${VERSION}[_${PKGREVISION}][-${EPOCH}] + * ${VERSION}[_${PKGREVISION}][:${EPOCH}] * ${EPOCH} supersedes ${VERSION} supersedes ${PKGREVISION}. * * The epoch and revision are defined to be a single number, while the rest diff --git a/lib/util.c b/lib/util.c index 72077625..5171e33b 100644 --- a/lib/util.c +++ b/lib/util.c @@ -183,6 +183,20 @@ xbps_check_is_installed_pkgname(const char *pkgname) return false; } +const char * +xbps_get_pkg_epoch(const char *pkg) +{ + const char *tmp; + + assert(pkg != NULL); + + tmp = strrchr(pkg, ':'); + if (tmp == NULL) + return NULL; + + return tmp + 1; /* skip first ':' */ +} + const char * xbps_get_pkg_version(const char *pkg) {