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:
@@ -102,7 +102,7 @@ main(int argc, char **argv)
|
||||
struct xbps_handle xh;
|
||||
struct xferstat xfer;
|
||||
const char *version, *rootdir = NULL, *confdir = NULL;
|
||||
char *pkgname, *filename;
|
||||
char pkgname[XBPS_NAME_SIZE], *filename;
|
||||
int flags = 0, c, rv = 0;
|
||||
const struct option longopts[] = {
|
||||
{ NULL, 0, NULL, 0 }
|
||||
@@ -197,14 +197,12 @@ main(int argc, char **argv)
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
pkgname = xbps_pkg_name(argv[1]);
|
||||
if (pkgname == NULL) {
|
||||
if (!xbps_pkg_name(pkgname, sizeof(pkgname), argv[1])) {
|
||||
fprintf(stderr,
|
||||
"Invalid string, expected <string>-<version>_<revision>\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("%s\n", pkgname);
|
||||
free(pkgname);
|
||||
} else if (strcmp(argv[0], "getpkgrevision") == 0) {
|
||||
/* Returns the revision of a pkg string */
|
||||
if (argc != 2)
|
||||
@@ -220,12 +218,10 @@ main(int argc, char **argv)
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
pkgname = xbps_pkgpattern_name(argv[1]);
|
||||
if (pkgname == NULL)
|
||||
if (!xbps_pkgpattern_name(pkgname, sizeof(pkgname), argv[1]))
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
printf("%s\n", pkgname);
|
||||
free(pkgname);
|
||||
} else if (strcmp(argv[0], "getpkgdepversion") == 0) {
|
||||
/* returns the version of a package pattern dependency */
|
||||
if (argc != 2)
|
||||
|
Reference in New Issue
Block a user