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

@@ -84,7 +84,7 @@ unpack_archive(struct xbps_handle *xhp,
size_t instbufsiz = 0, rembufsiz = 0;
ssize_t entry_size;
const char *entry_pname, *transact, *binpkg_pkgver;
char *pkgname, *buf = NULL;
char pkgname[XBPS_NAME_SIZE], *buf = NULL;
int ar_rv, rv, error, entry_type, flags;
bool preserve, update, file_exists, keep_conf_file;
bool skip_extract, force, xucd_stats;
@@ -102,8 +102,9 @@ unpack_archive(struct xbps_handle *xhp,
euid = geteuid();
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
abort();
}
if (xhp->flags & XBPS_FLAG_FORCE_UNPACK)
force = true;
@@ -550,8 +551,6 @@ out:
xbps_object_release(binpkg_propsd);
if (xbps_object_type(binpkg_filesd) == XBPS_TYPE_DICTIONARY)
xbps_object_release(binpkg_filesd);
if (pkgname != NULL)
free(pkgname);
if (instbuf != NULL)
free(instbuf);
if (rembuf != NULL)