libxbps: ABI/API break due to xbps_pkg{,pattern}_name changes.
The funcs xbps_pkg_name() and xbps_pkgpattern_name() were using malloc(3) to return the result, until now. They now have been changed to not allocate the result via malloc, the caller is responsible to provide a buffer at least of XBPS_NAME_SIZE (64). If for whatever reason the pkgname can't be guessed, returns false. This should avoid lots of small allocs around libxbps. New functions have the following prototype: bool xbps_pkg_name(char *dst, size_t len, const char *pkg) bool xbps_pkgpattern_name(char *dst, size_t len, const char *pkg) as suggested by @duncaen.
This commit is contained in:
@@ -90,28 +90,26 @@ xbps_configure_pkg(struct xbps_handle *xhp,
|
||||
bool update)
|
||||
{
|
||||
xbps_dictionary_t pkgd;
|
||||
char *pkgname;
|
||||
const char *p;
|
||||
char pkgname[XBPS_NAME_SIZE];
|
||||
int rv = 0;
|
||||
pkg_state_t state = 0;
|
||||
mode_t myumask;
|
||||
|
||||
assert(pkgver != NULL);
|
||||
|
||||
if ((pkgname = xbps_pkg_name(pkgver)) == NULL) {
|
||||
xbps_dbg_printf(xhp, "[configure] cannot guess "
|
||||
"pkgname for %s\n", pkgver);
|
||||
/* assume pkgver == pkgname */
|
||||
pkgname = strdup(pkgver);
|
||||
assert(pkgname);
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
||||
p = pkgver;
|
||||
} else {
|
||||
p = pkgname;
|
||||
}
|
||||
pkgd = xbps_pkgdb_get_pkg(xhp, pkgname);
|
||||
|
||||
pkgd = xbps_pkgdb_get_pkg(xhp, p);
|
||||
if (pkgd == NULL) {
|
||||
xbps_dbg_printf(xhp, "[configure] cannot find %s (%s) "
|
||||
"in pkgdb\n", pkgname, pkgver);
|
||||
free(pkgname);
|
||||
"in pkgdb\n", p, pkgver);
|
||||
return ENOENT;
|
||||
}
|
||||
free(pkgname);
|
||||
|
||||
rv = xbps_pkg_state_dictionary(pkgd, &state);
|
||||
xbps_dbg_printf(xhp, "%s: state %d rv %d\n", pkgver, state, rv);
|
||||
|
Reference in New Issue
Block a user