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:
Juan RP
2020-02-08 19:31:29 +01:00
parent 1cda3017c3
commit 6010a24de6
35 changed files with 377 additions and 435 deletions

View File

@@ -225,7 +225,7 @@ array_replace_dict(xbps_array_t array,
{
xbps_object_t obj;
const char *curpkgver;
char *curpkgname;
char curpkgname[XBPS_NAME_SIZE];
assert(xbps_object_type(array) == XBPS_TYPE_ARRAY);
assert(xbps_object_type(dict) == XBPS_TYPE_DICTIONARY);
@@ -249,17 +249,15 @@ array_replace_dict(xbps_array_t array,
/* pkgname match */
xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &curpkgver);
curpkgname = xbps_pkg_name(curpkgver);
assert(curpkgname);
if (!xbps_pkg_name(curpkgname, XBPS_NAME_SIZE, curpkgver)) {
abort();
}
if (strcmp(curpkgname, str) == 0) {
if (!xbps_array_set(array, i, dict)) {
free(curpkgname);
return EINVAL;
}
free(curpkgname);
return 0;
}
free(curpkgname);
}
}
/* no match */