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

@@ -37,7 +37,7 @@ remove_obj_from_array(xbps_array_t array, const char *str, int mode)
xbps_object_iterator_t iter;
xbps_object_t obj;
const char *curname, *pkgdep;
char *curpkgname;
char curpkgname[XBPS_NAME_SIZE];
unsigned int idx = 0;
bool found = false;
@@ -57,15 +57,13 @@ remove_obj_from_array(xbps_array_t array, const char *str, int mode)
} else if (mode == 1) {
/* match by pkgname, obj is a string */
pkgdep = xbps_string_cstring_nocopy(obj);
curpkgname = xbps_pkg_name(pkgdep);
if (curpkgname == NULL)
if (!xbps_pkg_name(curpkgname, sizeof(curpkgname), pkgdep))
break;
if (strcmp(curpkgname, str) == 0) {
free(curpkgname);
found = true;
break;
}
free(curpkgname);
} else if (mode == 2) {
/* match by pkgname, obj is a dictionary */
xbps_dictionary_get_cstring_nocopy(obj,