Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Merge remote-tracking branch 'upstream/main'
Shawn Webb committed 1 year ago
commit 2498431b467ef1c941b8b0ee79cdc24e6f5d6ba6
parent bf1eb68
25 files changed +340 -260
modified NEWS
@@ -1,6 +1,31 @@
+
Changes from 1.21.99.6 to 1.21.99.6
+
- ignore OSVERSION if set but ABI is not set
+

+
Changes from 1.21.99.4 to 1.21.99.5
+
- the pkg target ABI is now dynamically detected, pkg can be used to cross
+
  install packages among OS.
+
- macho ABI handling completly rewritten
+
- ALTABI is not used anywhere anymore, we are now only working with ABI
+
- Lots of cleanups thanks for compiler sanitizers
+
- shlibs handling is now portable (and do not depend on elfhints anymore)
+
- deprecate ALLOW_BASE_SHLIBS, now pkg scans for /lib and /usr/lib (respecting
+
  rootdir) to find the list of shlibs provided by base. This scan is skipped
+
  when using pkgbase.
+
- new SHLIB_REQUIRE_IGNORE_GLOB and SHLIB_REQUIRE_IGNORE_REGEX to filter out
+
  some librariries to be added to shlibs_required list
+
- speed up pkg repo by using buffered stdio
+
- pkg now tracks shlibs with tagging:
+
   libfoo.so.1.0.0          - native (no change to status quo)
+
   libfoo.so.1.0.0:32       - compat 32
+
   libfoo.so.1.0.0:Linux    - compat Linux
+
   libfoo.so.1.0.0:Linux:32 - compat Linux 32
+
- pkg tracks 32bit compat shlibs
+
- pkg can track linux shlibs for linux compatibility (disabled by default) via
+
  TRACK_LINUX_COMPAT_SHLIBS
+

Changes from 1.21.99.3 to 1.21.99.4
- ABI detection related fixes
-
- Lots of fixs for MacOS
+
- Lots of fixes for MacOS
- Fix host component handling in file:// URLs
- build system: add --with-tsan support
- fix threads on MacOS
modified auto.def
@@ -6,7 +6,7 @@ use cc cc-lib cc-shared pkg-config
set maj_ver 1
set med_ver 21
set min_ver 99
-
set dev_ver 3
+
set dev_ver 6
define PKG_API [expr {$maj_ver * 1000000 + $med_ver * 1000 + $min_ver}]
define VERSION $maj_ver.$med_ver.$min_ver[expr {$dev_ver ? ".$dev_ver" : ""}]

modified libpkg/Makefile.autosetup
@@ -189,7 +189,7 @@ lib$(LIB)_flat.a: $(STATIC_LIBS)
	libtool -static -o lib$(LIB)_flat.a $(STATIC_LIBS)
@else
lib$(LIB)_flat.a: ${STATIC_LIBS} mergelib_script
-
	ar -M < mergelib_script
+
	$(AR) -M < mergelib_script
@endif

mergelib_script: $(STATIC_LIBS)
@@ -209,5 +209,6 @@ install: all pkg.h lib$(LIB)$(LIBSOEXT) lib$(LIB)_flat.a
	ln -sf lib$(LIB)$(LIBSOEXT) $(DESTDIR)$(libdir)/lib$(LIB)$(SH_SOEXT)
	install -m 644 lib$(LIB)_flat.a $(DESTDIR)$(libdir)/lib$(LIB).a
	install -m 644 pkg.h $(DESTDIR)$(includedir)/
+
	install -m 644 $(top_srcdir)/libpkg/pkg/vec.h $(DESTDIR)$(includedir)/pkg
	install -m 644 $(top_srcdir)/libpkg/pkg/audit.h $(DESTDIR)$(includedir)/pkg
	install -m 644 pkg.pc $(DESTDIR)$(pkgconfigdir)/
modified libpkg/pkg.h.in
@@ -46,7 +46,7 @@ extern "C" {
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
-
#include <pkgvec.h>
+
#include <pkg/vec.h>

/* The expected name of the pkg(8) binary executable. */
#ifndef PKG_EXEC_NAME
@@ -136,7 +136,7 @@ struct pkg_kv {
	char *value;
};

-
typedef pkgvec_t(struct pkg_kv *) pkg_kvl_t;
+
typedef vec_t(struct pkg_kv *) pkg_kvl_t;

/**
 * The system-wide pkg(8) status: ie. is it a) installed or otherwise
added libpkg/pkg/vec.h
@@ -0,0 +1,71 @@
+
/*-
+
 * Copyright(c) 2024 Baptiste Daroussin <bapt@FreeBSD.org>
+
 *
+
 * SPDX-License-Identifier: BSD-2-Clause
+
 */
+

+
#pragma once
+

+
#include <stdbool.h>
+
#include <stdlib.h>
+
#include <stddef.h>
+

+
#define vec_t(Type) \
+
  struct { Type *d; size_t len, cap; }
+

+
#define vec_init(v) \
+
	memset((v), 0, sizeof(*(v)))
+

+
#define vec_free(v) \
+
	do { \
+
		free((v)->d); \
+
		(v)->d == NULL; \
+
		memset((v), 0, sizeof(*(v))); \
+
	} while (0)
+

+
#define vec_free_and_free(v, free_func)            \
+
	do {                                          \
+
		for (size_t _i=0; _i < (v)->len ; _i++) { \
+
			free_func((v)->d[_i]);          \
+
			(v)->d[_i] = NULL;   \
+
		}                                     \
+
		vec_free((v)); \
+
	} while(0)
+

+
#define vec_first(v) \
+
	(v)->d[0]
+

+
#define vec_last(v) \
+
	(v)->d[(v)->len -1]
+

+
#define vec_clear(v) \
+
	(v)->len = 0
+

+
#define vec_clear_and_free(v, free_func) \
+
	do {                                          \
+
		for (size_t _i=0; _i < (v)->len ; _i++) { \
+
			free_func((v)->d[_i]);          \
+
			(v)->d[_i] = NULL;   \
+
		}                                     \
+
		(v)->len = 0;                            \
+
	} while (0)
+

+
#define vec_push(v, _d)                                            \
+
	do {                                                          \
+
		if ((v)->len + 1 > (v)->cap) {                            \
+
			if ((v)->cap == 0)                              \
+
				(v)->cap = 1;                          \
+
			else                                          \
+
				(v)->cap *=2;                           \
+
			(v)->d = realloc((v)->d, (v)->cap * sizeof(*(v)->d)); \
+
			if ((v)->d == NULL)                             \
+
				abort();                              \
+
		}                                                     \
+
		(v)->d[(v)->len++] = (_d);                                  \
+
	} while (0)                                                   \
+

+
#define vec_pop(v) \
+
	(v)->d[--(v)->len]
+

+
typedef vec_t(char *) charv_t;
+
typedef vec_t(const char *) c_charv_t;
modified libpkg/pkg_add.c
@@ -446,20 +446,21 @@ reopen_tempdir(int rootfd, struct tempdir *t)
}

static struct tempdir *
-
get_tempdir(int rootfd, const char *path, tempdirs_t *tempdirs, stringlist_t *symlinks_allowed)
+
get_tempdir(int rootfd, const char *path, tempdirs_t *tempdirs, c_charv_t *symlinks_allowed)
{
	struct tempdir *tmpdir = NULL;

-
	tll_foreach(*tempdirs, t) {
-
		if (strncmp(t->item->name, path, t->item->len) == 0 && path[t->item->len] == '/') {
-
			reopen_tempdir(rootfd, t->item);
-
			return (t->item);
+
	for (size_t i = 0; i < tempdirs->len; i++) {
+
		tmpdir = tempdirs->d[i];
+
		if (strncmp(tmpdir->name, path, tmpdir->len) == 0 && path[tmpdir->len] == '/') {
+
			reopen_tempdir(rootfd, tmpdir);
+
			return (tmpdir);
		}
	}

	tmpdir = open_tempdir(rootfd, path, symlinks_allowed);
	if (tmpdir != NULL)
-
		tll_push_back(*tempdirs, tmpdir);
+
		vec_push(tempdirs, tmpdir);

	return (tmpdir);
}
@@ -475,7 +476,7 @@ close_tempdir(struct tempdir *t)
}

static int
-
create_dir(struct pkg *pkg, struct pkg_dir *d, tempdirs_t *tempdirs, stringlist_t *symlinks_allowed)
+
create_dir(struct pkg *pkg, struct pkg_dir *d, tempdirs_t *tempdirs, c_charv_t *symlinks_allowed)
{
	struct stat st;
	struct tempdir *tmpdir = NULL;
@@ -525,7 +526,7 @@ create_dir(struct pkg *pkg, struct pkg_dir *d, tempdirs_t *tempdirs, stringlist_
/* In case of directories create the dir and extract the creds */
static int
do_extract_dir(struct pkg* pkg, struct archive *a __unused, struct archive_entry *ae,
-
    const char *path, struct pkg *local __unused, tempdirs_t *tempdirs, stringlist_t *symlinks_allowed)
+
    const char *path, struct pkg *local __unused, tempdirs_t *tempdirs, c_charv_t *symlinks_allowed)
{
	struct pkg_dir *d;
	const struct stat *aest;
@@ -571,7 +572,7 @@ try_mkdir(int fd, const char *path)

static int
create_symlinks(struct pkg *pkg, struct pkg_file *f, const char *target, tempdirs_t *tempdirs,
-
    stringlist_t *symlinks_allowed)
+
    c_charv_t *symlinks_allowed)
{
	struct tempdir *tmpdir = NULL;
	int fd;
@@ -618,7 +619,7 @@ retry:
static int
do_extract_symlink(struct pkg *pkg, struct archive *a __unused, struct archive_entry *ae,
    const char *path, struct pkg *local __unused, tempdirs_t *tempdirs,
-
    stringlist_t *symlinks_allowed)
+
    c_charv_t *symlinks_allowed)
{
	struct pkg_file *f;
	const struct stat *aest;
@@ -650,7 +651,7 @@ do_extract_symlink(struct pkg *pkg, struct archive *a __unused, struct archive_e

static int
create_hardlink(struct pkg *pkg, struct pkg_file *f, const char *path, tempdirs_t *tempdirs,
-
    stringlist_t *symlinks_allowed)
+
    c_charv_t *symlinks_allowed)
{
	bool tried_mkdir = false;
	struct pkg_file *fh;
@@ -675,10 +676,10 @@ create_hardlink(struct pkg *pkg, struct pkg_file *f, const char *path, tempdirs_
		return (EPKG_FATAL);
	}
	if (fh->temppath[0] == '\0') {
-
		tll_foreach(*tempdirs, t) {
-
			if (strncmp(t->item->name, fh->path, t->item->len) == 0 &&
-
			    fh->path[t->item->len] == '/' ) {
-
				tmphdir = t->item;
+
		for (size_t i = 0; i < tempdirs->len; i++) {
+
			if (strncmp(tempdirs->d[i]->name, fh->path, tempdirs->d[i]->len) == 0 &&
+
			    fh->path[tempdirs->d[i]->len] == '/' ) {
+
				tmphdir = tempdirs->d[i];
				reopen_tempdir(pkg->rootfd, tmphdir);
				break;
			}
@@ -726,7 +727,7 @@ retry:
static int
do_extract_hardlink(struct pkg *pkg, struct archive *a __unused, struct archive_entry *ae,
    const char *path, struct pkg *local __unused, tempdirs_t *tempdirs,
-
    stringlist_t *symlinks_allowed)
+
    c_charv_t *symlinks_allowed)
{
	struct pkg_file *f;
	const struct stat *aest;
@@ -773,7 +774,7 @@ retry:
static int
create_regfile(struct pkg *pkg, struct pkg_file *f, struct archive *a,
    struct archive_entry *ae, int fromfd, struct pkg *local, tempdirs_t *tempdirs,
-
    stringlist_t *symlinks_allowed)
+
    c_charv_t *symlinks_allowed)
{
	int fd = -1;
	size_t len;
@@ -888,7 +889,7 @@ create_regfile(struct pkg *pkg, struct pkg_file *f, struct archive *a,

static int
do_extract_regfile(struct pkg *pkg, struct archive *a, struct archive_entry *ae,
-
    const char *path, struct pkg *local, tempdirs_t *tempdirs, stringlist_t *symlinks_allowed)
+
    const char *path, struct pkg *local, tempdirs_t *tempdirs, c_charv_t *symlinks_allowed)
{
	struct pkg_file *f;
	const struct stat *aest;
@@ -921,14 +922,14 @@ do_extract_regfile(struct pkg *pkg, struct archive *a, struct archive_entry *ae,
static int
do_extract(struct archive *a, struct archive_entry *ae,
    int nfiles, struct pkg *pkg, struct pkg *local, tempdirs_t *tempdirs,
-
    stringlist_t *symlinks_allowed)
+
    c_charv_t *symlinks_allowed)
{
	int	retcode = EPKG_OK;
	int	ret = 0, cur_file = 0;
	char	path[MAXPATHLEN];
	int (*extract_cb)(struct pkg *pkg, struct archive *a,
	    struct archive_entry *ae, const char *path, struct pkg *local,
-
	    tempdirs_t *tempdirs, stringlist_t *sa);
+
	    tempdirs_t *tempdirs, c_charv_t *sa);

#ifndef HAVE_ARC4RANDOM
	srand(time(NULL));
@@ -1064,13 +1065,14 @@ pkg_extract_finalize(struct pkg *pkg, tempdirs_t *tempdirs)


	if (tempdirs != NULL) {
-
		tll_foreach(*tempdirs, t) {
-
			if (renameat(pkg->rootfd, RELATIVE_PATH(t->item->temp),
-
			    pkg->rootfd, RELATIVE_PATH(t->item->name)) != 0) {
+
		for (size_t i = 0; i < tempdirs->len; i++) {
+
			struct tempdir *t = tempdirs->d[i];
+
			if (renameat(pkg->rootfd, RELATIVE_PATH(t->temp),
+
			    pkg->rootfd, RELATIVE_PATH(t->name)) != 0) {
				pkg_fatal_errno("Fail to rename %s -> %s",
-
				    t->item->temp, t->item->name);
+
				    t->temp, t->name);
			}
-
			free(t->item);
+
			free(t);
		}
	}
	while (pkg_files(pkg, &f) == EPKG_OK) {
@@ -1134,7 +1136,7 @@ pkg_extract_finalize(struct pkg *pkg, tempdirs_t *tempdirs)
			return (EPKG_FATAL);
	}
	if (tempdirs != NULL)
-
		tll_free(*tempdirs);
+
		vec_free(tempdirs);

	return (EPKG_OK);
}
@@ -1401,11 +1403,14 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
	int			 retcode = EPKG_OK;
	int			 ret;
	int			 nfiles;
-
	tempdirs_t		 tempdirs = tll_init();
-
	stringlist_t		 symlinks_allowed = tll_init();
+
	tempdirs_t		 tempdirs;
+
	c_charv_t		 symlinks_allowed;

	assert(path != NULL);

+
	vec_init(&tempdirs);
+
	vec_init(&symlinks_allowed);
+

	/*
	 * Open the package archive file, read all the meta files and set the
	 * current archive_entry to the first non-meta file.
@@ -1507,7 +1512,7 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
	 */
	if (extract) {
		pkg_register_cleanup_callback(pkg_rollback_cb, pkg);
-
		tll_push_back(symlinks_allowed, pkg->prefix);
+
		vec_push(&symlinks_allowed, pkg->prefix);
		retcode = do_extract(a, ae, nfiles, pkg, local, &tempdirs, &symlinks_allowed);
		pkg_unregister_cleanup_callback(pkg_rollback_cb, pkg);
		if (retcode != EPKG_OK) {
@@ -1606,7 +1611,7 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
	}

cleanup:
-
	tll_free(symlinks_allowed);
+
	vec_free(&symlinks_allowed);

	if (openxact)
		pkgdb_register_finale(db, retcode, NULL);
@@ -1699,15 +1704,18 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
	struct group *gr, grent;
	int err, fd, fromfd;
	int retcode;
-
	hardlinks_t hardlinks = tll_init();
+
	hardlinks_t hardlinks;
	const char *path;
	char buffer[1024];
	size_t link_len;
	bool install_as_user;
-
	tempdirs_t tempdirs = tll_init();
-
	stringlist_t symlinks_allowed = tll_init();
-
	tll_push_back(symlinks_allowed, pkg->prefix);
+
	tempdirs_t tempdirs;
+
	c_charv_t symlinks_allowed;

+
	vec_init(&symlinks_allowed);
+
	vec_push(&symlinks_allowed, pkg->prefix);
+
	vec_init(&hardlinks);
+
	vec_init(&tempdirs);
	install_as_user = (getenv("INSTALL_AS_USER") != NULL);

	fromfd = open(src, O_DIRECTORY);
@@ -1775,7 +1783,7 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
			continue;
		if (fstatat(fromfd, RELATIVE_PATH(f->path), &st,
		    AT_SYMLINK_NOFOLLOW) == -1) {
-
			tll_free_and_free(hardlinks, free);
+
			vec_free_and_free(&hardlinks, free);
			close(fromfd);
			pkg_fatal_errno("%s%s", src, f->path);
		}
@@ -1828,7 +1836,7 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
			if ((link_len = readlinkat(fromfd,
			    RELATIVE_PATH(f->path), target,
			    sizeof(target))) == -1) {
-
				tll_free_and_free(hardlinks, free);
+
				vec_free_and_free(&hardlinks, free);
				close(fromfd);
				pkg_fatal_errno("Impossible to read symlinks "
				    "'%s'", f->path);
@@ -1841,16 +1849,17 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
		} else if (S_ISREG(st.st_mode)) {
			if ((fd = openat(fromfd, RELATIVE_PATH(f->path),
			    O_RDONLY)) == -1) {
-
				tll_free_and_free(hardlinks, free);
+
				vec_free_and_free(&hardlinks, free);
				close(fromfd);
				pkg_fatal_errno("Impossible to open source file"
				    " '%s'", RELATIVE_PATH(f->path));
			}
			path = NULL;
-
			tll_foreach(hardlinks, hit) {
-
				if (hit->item->ino == st.st_ino &&
-
				    hit->item->dev == st.st_dev) {
-
					path = hit->item->path;
+
			for (size_t i = 0; i < hardlinks.len; i++) {
+
				struct hardlink *hit = hardlinks.d[i];
+
				if (hit->ino == st.st_ino &&
+
				    hit->dev == st.st_dev) {
+
					path = hit->path;
					break;
				}
			}
@@ -1870,7 +1879,7 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
				h->ino = st.st_ino;
				h->dev = st.st_dev;
				h->path = f->path;
-
				tll_push_back(hardlinks, h);
+
				vec_push(&hardlinks, h);
			}
			close(fd);
		} else {
@@ -1883,8 +1892,8 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
	retcode = pkg_extract_finalize(pkg, &tempdirs);

cleanup:
-
	tll_free(symlinks_allowed);
-
	tll_free_and_free(hardlinks, free);
+
	vec_free(&symlinks_allowed);
+
	vec_free_and_free(&hardlinks, free);
	close(fromfd);
	return (retcode);
}
modified libpkg/pkg_config.c
@@ -362,13 +362,11 @@ static struct config_entry c[] = {
		"METALOG",
		NULL,
	},
-
#ifdef __FreeBSD__
	{
		PKG_BOOL,
		"IGNORE_OSVERSION",
		"NO",
	},
-
#endif
	{
		PKG_BOOL,
		"BACKUP_LIBRARIES",
@@ -529,10 +527,10 @@ pkg_external_libs_version(void)
{
	pkg_kvl_t *kvl = xcalloc(1, sizeof(*kvl));

-
	pkgvec_push(kvl, pkg_kv_new("libcurl", curl_version()));
-
	pkgvec_push(kvl, pkg_kv_new("libarchive", archive_version_string()));
-
	pkgvec_push(kvl, pkg_kv_new("sqlite", sqlite3_libversion()));
-
	pkgvec_push(kvl, pkg_kv_new("openssl", OpenSSL_version(OPENSSL_VERSION)));
+
	vec_push(kvl, pkg_kv_new("libcurl", curl_version()));
+
	vec_push(kvl, pkg_kv_new("libarchive", archive_version_string()));
+
	vec_push(kvl, pkg_kv_new("sqlite", sqlite3_libversion()));
+
	vec_push(kvl, pkg_kv_new("openssl", OpenSSL_version(OPENSSL_VERSION)));

	return (kvl);
}
@@ -1066,10 +1064,11 @@ config_init_abi(struct pkg_abi *abi)
				    pkg_os_to_string(abi->os));
			}
		}
-
	} else if (env_osversion_string != NULL) {
-
		pkg_emit_error("Setting OSVERSION requires setting ABI as well");
-
		return (EPKG_FATAL);
	} else {
+
		if (env_osversion_string != NULL) {
+
			dbg(1, "Setting OSVERSION requires setting ABI as well (ignoring)");
+
			unsetenv("OSVERSION");
+
		}
		if (pkg_abi_from_file(abi) != EPKG_OK) {
			return (false);
		}
modified libpkg/pkg_create.c
@@ -68,8 +68,9 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
	const char	*relocation;
	char		*manifest;
	ucl_object_t	*obj;
-
	hardlinks_t	 hardlinks = tll_init();
+
	hardlinks_t	 hardlinks;

+
	vec_init(&hardlinks);
	if (pkg_is_valid(pkg) != EPKG_OK) {
		pkg_emit_error("the package is not valid");
		return (EPKG_FATAL);
@@ -95,13 +96,13 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,

		if (lstat(fpath, &st) == -1) {
			pkg_emit_error("file '%s' is missing", fpath);
-
			tll_free_and_free(hardlinks, free);
+
			vec_free_and_free(&hardlinks, free);
			return (EPKG_FATAL);
		}

		if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))) {
			pkg_emit_error("file '%s' is not a regular file or symlink", fpath);
-
			tll_free_and_free(hardlinks, free);
+
			vec_free_and_free(&hardlinks, free);
			return (EPKG_FATAL);
		}

@@ -116,13 +117,13 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
		file->sum = pkg_checksum_generate_file(fpath,
		    PKG_HASH_TYPE_SHA256_HEX);
		if (file->sum == NULL) {
-
			tll_free_and_free(hardlinks, free);
+
			vec_free_and_free(&hardlinks, free);
			return (EPKG_FATAL);
		}

		counter_count();
	}
-
	tll_free_and_free(hardlinks, free);
+
	vec_free_and_free(&hardlinks, free);

	counter_end();

modified libpkg/pkg_jobs.c
@@ -29,7 +29,6 @@
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

-
#include "pkgvec.h"
#ifdef HAVE_CONFIG_H
#include "pkg_config.h"
#endif
@@ -121,9 +120,9 @@ int
pkg_jobs_set_repository(struct pkg_jobs *j, const char *ident)
{
	c_charv_t idents;
-
	pkgvec_init(&idents);
+
	vec_init(&idents);
	if (ident != NULL)
-
		pkgvec_push(&idents, ident);
+
		vec_push(&idents, ident);
	return (pkg_jobs_set_repositories(j, &idents));
}

modified libpkg/pkg_ports.c
@@ -1046,6 +1046,7 @@ plist_new(struct pkg *pkg, const char *stage)
	p->post_install_buf = xstring_new();
	p->pre_deinstall_buf = xstring_new();
	p->post_deinstall_buf = xstring_new();
+
	vec_init(&p->hardlinks);

	populate_keywords(p);

@@ -1071,7 +1072,7 @@ plist_free(struct plist *p)

	free(p->uname);
	free(p->gname);
-
	tll_free_and_free(p->hardlinks, free);
+
	vec_free_and_free(&p->hardlinks, free);

	xstring_free(p->post_deinstall_buf);
	xstring_free(p->post_install_buf);
modified libpkg/pkgdb.c
@@ -51,7 +51,7 @@
#include "private/utils.h"
#include "private/pkg_deps.h"
#include "tllist.h"
-
#include "pkgvec.h"
+
#include "pkg/vec.h"

#include "private/db_upgrades.h"

@@ -987,12 +987,12 @@ pkgdb_open_all(struct pkgdb **db_p, pkgdb_t type, const char *reponame)
	c_charv_t r;
	int ret;

-
	pkgvec_init(&r);
+
	vec_init(&r);
	if (reponame != NULL)
-
		pkgvec_push(&r, reponame);
+
		vec_push(&r, reponame);

	ret = pkgdb_open_all2(db_p, type, &r);
-
	pkgvec_free(&r);
+
	vec_free(&r);
	return (ret);
}
int
modified libpkg/pkgdb_query.c
@@ -34,7 +34,7 @@
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

-
#include "pkgvec.h"
+
#include "pkg/vec.h"
#ifdef HAVE_CONFIG_H
#include "pkg_config.h"
#endif
@@ -401,13 +401,13 @@ pkgdb_repo_query_cond(struct pkgdb *db, const char *cond, const char *pattern, m
	c_charv_t r;
	struct pkgdb_it *ret;

-
	pkgvec_init(&r);
+
	vec_init(&r);

	if (repo != NULL)
-
		pkgvec_push(&r, repo);
+
		vec_push(&r, repo);

	ret = pkgdb_repo_query_cond2(db, cond, pattern, match, &r);
-
	pkgvec_free(&r);
+
	vec_free(&r);

	return (ret);
}
@@ -548,12 +548,12 @@ pkgdb_repo_search(struct pkgdb *db, const char *pattern, match_t match,
	c_charv_t r;
	struct pkgdb_it *ret;

-
	pkgvec_init(&r);
+
	vec_init(&r);
	if (repo != NULL)
-
		pkgvec_push(&r, repo);
+
		vec_push(&r, repo);

	ret = pkgdb_repo_search2(db, pattern, match, field, sort, &r);
-
	pkgvec_free(&r);
+
	vec_free(&r);

	return (ret);
}
@@ -595,14 +595,14 @@ pkgdb_all_search(struct pkgdb *db, const char *pattern, match_t match,
	c_charv_t r;
	struct pkgdb_it *ret;

-
	pkgvec_init(&r);
+
	vec_init(&r);

	if (repo != NULL)
-
		pkgvec_push(&r, repo);
+
		vec_push(&r, repo);

	ret = pkgdb_all_search2(db, pattern, match, field, sort, &r);

-
	pkgvec_free(&r);
+
	vec_free(&r);

	return (ret);
}
deleted libpkg/pkgvec.h
@@ -1,71 +0,0 @@
-
/*-
-
 * Copyright(c) 2024 Baptiste Daroussin <bapt@FreeBSD.org>
-
 *
-
 * SPDX-License-Identifier: BSD-2-Clause
-
 */
-

-
#pragma once
-

-
#include <stdbool.h>
-
#include <stdlib.h>
-
#include <stddef.h>
-

-
#define pkgvec_t(Type) \
-
  struct { Type *d; size_t len, cap; }
-

-
#define pkgvec_init(v) \
-
	memset((v), 0, sizeof(*(v)))
-

-
#define pkgvec_free(v) \
-
	do { \
-
		free((v)->d); \
-
		(v)->d == NULL; \
-
		memset((v), 0, sizeof(*(v))); \
-
	} while (0)
-

-
#define pkgvec_free_and_free(v, free_func)            \
-
	do {                                          \
-
		for (size_t _i=0; _i < (v)->len ; _i++) { \
-
			free_func((v)->d[_i]);          \
-
			(v)->d[_i] = NULL;   \
-
		}                                     \
-
		pkgvec_free((v)); \
-
	} while(0)
-

-
#define pkgvec_first(v) \
-
	(v)->d[0]
-

-
#define pkgvec_last(v) \
-
	(v)->d[(v)->len -1]
-

-
#define pkgvec_clear(v) \
-
	(v)->len = 0
-

-
#define pkgvec_clear_and_free(v, free_func) \
-
	do {                                          \
-
		for (size_t _i=0; _i < (v)->len ; _i++) { \
-
			free_func((v)->d[_i]);          \
-
			(v)->d[_i] = NULL;   \
-
		}                                     \
-
		(v)->len = 0;                            \
-
	} while (0)
-

-
#define pkgvec_push(v, _d)                                            \
-
	do {                                                          \
-
		if ((v)->len + 1 > (v)->cap) {                            \
-
			if ((v)->cap == 0)                              \
-
				(v)->cap = 1;                          \
-
			else                                          \
-
				(v)->cap *=2;                           \
-
			(v)->d = realloc((v)->d, (v)->cap * sizeof(*(v)->d)); \
-
			if ((v)->d == NULL)                             \
-
				abort();                              \
-
		}                                                     \
-
		(v)->d[(v)->len++] = (_d);                                  \
-
	} while (0)                                                   \
-

-
#define pkgvec_pop(v) \
-
	(v)->d[--(v)->len]
-

-
typedef pkgvec_t(char *) charv_t;
-
typedef pkgvec_t(const char *) c_charv_t;
modified libpkg/private/utils.h
@@ -53,12 +53,12 @@ typedef tll(char *) stringlist_t;
	__FILE__, __LINE__, sqlite3_errmsg(db)); \
} while (0)

-
typedef tll(struct hardlink *) hardlinks_t;
struct hardlink {
	ino_t ino;
	dev_t dev;
	const char *path;
};
+
typedef vec_t(struct hardlink *) hardlinks_t;

struct tempdir {
	char name[PATH_MAX];
@@ -66,7 +66,7 @@ struct tempdir {
	size_t len;
	int fd;
};
-
typedef tll(struct tempdir *) tempdirs_t;
+
typedef vec_t(struct tempdir *) tempdirs_t;

struct dns_srvinfo {
	unsigned int type;
@@ -116,7 +116,7 @@ char *rtrimspace(char *buf);
void hidden_tempfile(char *buf, int buflen, const char *path);
void append_random_suffix(char *buf, int buflen, int suffixlen);
char *json_escape(const char *str);
-
struct tempdir *open_tempdir(int rootfd, const char *path, stringlist_t *strlist);
+
struct tempdir *open_tempdir(int rootfd, const char *path, c_charv_t *strlist);
const char *get_http_auth(void);
bool c_charv_contains(c_charv_t *, const char *, bool);

modified libpkg/utils.c
@@ -53,7 +53,7 @@
#include <bsd_compat.h>

#include "pkg.h"
-
#include "pkgvec.h"
+
#include "pkg/vec.h"
#include "private/event.h"
#include "private/pkg_abi.h"
#include "private/utils.h"
@@ -323,15 +323,16 @@ check_for_hardlink(hardlinks_t *hl, struct stat *st)
{
	struct hardlink *h;

-
	tll_foreach(*hl, it) {
-
		if (it->item->ino == st->st_ino &&
-
		    it->item->dev == st->st_dev)
+
	for (size_t i = 0; i < hl->len; i++) {
+
		h = hl->d[i];
+
		if (h->ino == st->st_ino &&
+
		    h->dev == st->st_dev)
			return (true);
	}
	h = xcalloc(1, sizeof(*h));
	h->ino = st->st_ino;
	h->dev = st->st_dev;
-
	tll_push_back(*hl, h);
+
	vec_push(hl, h);

	return (false);
}
@@ -983,7 +984,7 @@ json_escape(const char *str)
}

struct tempdir *
-
open_tempdir(int rootfd, const char *path, stringlist_t *symlinks_allowed)
+
open_tempdir(int rootfd, const char *path, c_charv_t *symlinks_allowed)
{
	struct stat st;
	char walk[MAXPATHLEN];
@@ -1002,8 +1003,8 @@ open_tempdir(int rootfd, const char *path, stringlist_t *symlinks_allowed)
		if (len > 0) {
			int flag = AT_SYMLINK_NOFOLLOW;
			if (symlinks_allowed != NULL) {
-
				tll_foreach(*symlinks_allowed, t) {
-
					if (STREQ(RELATIVE_PATH(walk), RELATIVE_PATH(t->item)))
+
				for (size_t i = 0; i < symlinks_allowed->len; i++) {
+
					if (STREQ(RELATIVE_PATH(walk), RELATIVE_PATH(symlinks_allowed->d[i])))
						flag = 0;
				}
			}
modified src/fetch.c
@@ -82,7 +82,7 @@ exec_fetch(int argc, char **argv)
		{ NULL,			0,			NULL,	0   },
	};

-
	pkgvec_init(&reponames);
+
	vec_init(&reponames);
	while ((ch = getopt_long(argc, argv, "+aCdgiqr:Uuxyo:", longopts, NULL)) != -1) {
		switch (ch) {
		case 'a':
@@ -104,7 +104,7 @@ exec_fetch(int argc, char **argv)
			quiet = true;
			break;
		case 'r':
-
			pkgvec_push(&reponames, optarg);
+
			vec_push(&reponames, optarg);
			break;
		case 'u':
			f |= PKG_FLAG_UPGRADES_FOR_INSTALLED;
modified src/install.c
@@ -98,7 +98,7 @@ exec_install(int argc, char **argv)
		quiet = true;
	}

-
	pkgvec_init(&reponames);
+
	vec_init(&reponames);
	while ((ch = getopt_long(argc, argv, "+ACfFgiIlMnqr:RUxy", longopts, NULL)) != -1) {
		switch (ch) {
		case 'A':
@@ -139,7 +139,7 @@ exec_install(int argc, char **argv)
			quiet = true;
			break;
		case 'r':
-
			pkgvec_push(&reponames, optarg);
+
			vec_push(&reponames, optarg);
			break;
		case 'R':
			f |= PKG_FLAG_RECURSIVE;
modified src/pkgcli.h
@@ -14,7 +14,7 @@
#include <string.h>
#include <xstring.h>
#include <bsd_compat.h>
-
#include <pkgvec.h>
+
#include <pkg/vec.h>

#define pkg_warnx(fmt, ...) pkg_fprintf(stderr, "%S: " fmt, getprogname(), __VA_ARGS__, -1)
#define ll_foreach(head, el) for (el=head; el != NULL; el = (el)->next)
modified src/rquery.c
@@ -138,7 +138,7 @@ exec_rquery(int argc, char **argv)

	portsdir = pkg_object_string(pkg_config_get("PORTSDIR"));

-
	pkgvec_init(&reponames);
+
	vec_init(&reponames);
	while ((ch = getopt_long(argc, argv, "+aCgiIxe:r:U", longopts, NULL)) != -1) {
		switch (ch) {
		case 'a':
@@ -160,7 +160,7 @@ exec_rquery(int argc, char **argv)
			index_output = true;
			break;
		case 'r':
-
			pkgvec_push(&reponames, optarg);
+
			vec_push(&reponames, optarg);
			break;
		case 'U':
			auto_update = false;
modified src/search.c
@@ -280,7 +280,7 @@ exec_search(int argc, char **argv)
		{ NULL,			0,			NULL,	0   },
	};

-
	pkgvec_init(&reponames);
+
	vec_init(&reponames);
	while ((ch = getopt_long(argc, argv, "+CcDdefgiL:opqQ:r:RS:sUx", longopts, NULL)) != -1) {
		switch (ch) {
		case 'C':
@@ -323,7 +323,7 @@ exec_search(int argc, char **argv)
			opt |= modifier_opt(optarg);
			break;
		case 'r':
-
			pkgvec_push(&reponames, optarg);
+
			vec_push(&reponames, optarg);
			break;
		case 'R':
			opt = INFO_RAW;
modified src/update.c
@@ -158,7 +158,7 @@ exec_update(int argc, char **argv)
		{ NULL,		0,			NULL,	0   },
	};

-
	pkgvec_init(&reponames);
+
	vec_init(&reponames);
	while ((ch = getopt_long(argc, argv, "+fqr:", longopts, NULL)) != -1) {
		switch (ch) {
		case 'f':
@@ -168,7 +168,7 @@ exec_update(int argc, char **argv)
			quiet = true;
			break;
		case 'r':
-
			pkgvec_push(&reponames, optarg);
+
			vec_push(&reponames, optarg);
			break;
		default:
			usage_update();
modified src/upgrade.c
@@ -268,7 +268,7 @@ exec_upgrade(int argc, char **argv)
	};

	nbactions = nbdone = 0;
-
	pkgvec_init(&reponames);
+
	vec_init(&reponames);

	while ((ch = getopt_long(argc, argv, "+CfFgiInqr:Uxyv", longopts, NULL)) != -1) {
		switch (ch) {
@@ -300,7 +300,7 @@ exec_upgrade(int argc, char **argv)
			quiet = true;
			break;
		case 'r':
-
			pkgvec_push(&reponames, optarg);
+
			vec_push(&reponames, optarg);
			break;
		case 'U':
			auto_update = false;
modified src/version.c
@@ -831,7 +831,7 @@ exec_version(int argc, char **argv)
		{ NULL,			0,			NULL,	0   },
	};

-
	pkgvec_init(&reponames);
+
	vec_init(&reponames);
	while ((ch = getopt_long(argc, argv, "+Ce:g:hIiL:l:n:O:oPqRr:TtUvx:",
				 longopts, NULL)) != -1) {
		switch (ch) {
@@ -885,7 +885,7 @@ exec_version(int argc, char **argv)
			break;
		case 'r':
			opt |= VERSION_SOURCE_REMOTE;
-
			pkgvec_push(&reponames, optarg);
+
			vec_push(&reponames, optarg);
			break;
		case 'T':
			opt |= VERSION_TESTPATTERN;
added tests/lib/hash.c
@@ -0,0 +1,44 @@
+
/*
+
 * Copyright (c) 2024 Baptiste Daroussin <bapt@FreeBSD.org>
+
 *
+
 * SPDX-License-Identifier: BSD-2-Clause
+
 */
+

+
#include <atf-c.h>
+
#include <pkghash.h>
+
#include <xmalloc.h>
+

+
ATF_TC_WITHOUT_HEAD(hash);
+

+
ATF_TC_BODY(hash, tc)
+
{
+
	struct pkghash *h = pkghash_new();
+
	ATF_REQUIRE_EQ(pkghash_count(h), 0);
+
	ATF_REQUIRE(pkghash_add(h, "key", "value", NULL));
+
	ATF_REQUIRE_EQ(pkghash_count(h), 1);
+
	ATF_REQUIRE(!pkghash_del(h, "plop"));
+
	ATF_REQUIRE_EQ(pkghash_count(h), 1);
+
	ATF_REQUIRE(pkghash_del(h, "key"));
+
	ATF_REQUIRE_EQ(pkghash_count(h), 0);
+
	char *val = xstrdup("value");
+
	ATF_REQUIRE(pkghash_add(h, "key", val, free));
+
	ATF_REQUIRE_EQ(pkghash_count(h), 1);
+
	ATF_REQUIRE_STREQ((char *)pkghash_delete(h, "key"), "value");
+
	ATF_REQUIRE_STREQ(val, "value");
+
	ATF_REQUIRE_EQ(pkghash_count(h), 0);
+
	ATF_REQUIRE(pkghash_add(h, "key", val, free));
+
	ATF_REQUIRE_EQ(pkghash_count(h), 1);
+
	ATF_REQUIRE(pkghash_del(h, "key"));
+
	ATF_REQUIRE_EQ(pkghash_count(h), 0);
+
	val = xstrdup("value");
+
	ATF_REQUIRE(pkghash_add(h, "key", val, free));
+
	ATF_REQUIRE_EQ(pkghash_delete(h, "bla"), NULL);
+
	pkghash_destroy(h);
+
}
+

+
ATF_TP_ADD_TCS(tp)
+
{
+
	ATF_TP_ADD_TC(tp, hash);
+

+
	return (atf_no_error());
+
}
modified tests/lib/vec.c
@@ -6,8 +6,8 @@

#include <atf-c.h>
#include <private/utils.h>
-
#include <pkgvec.h>
#include <xmalloc.h>
+
#include <pkg/vec.h>

ATF_TC_WITHOUT_HEAD(c_charv_t);
ATF_TC_WITHOUT_HEAD(c_charv_contains);
@@ -17,107 +17,107 @@ ATF_TC_BODY(c_charv_t, tc)
{
	c_charv_t list;

-
	pkgvec_init(&list);
-
	ATF_REQUIRE_EQ_MSG(list.d, NULL, "pkgvec_init failed");
-
	ATF_REQUIRE_EQ_MSG(list.cap, 0, "pkgvec_init failed");
-
	ATF_REQUIRE_EQ_MSG(list.len, 0, "pkgvec_init failed");
-

-
	pkgvec_push(&list, "test1");
-
	ATF_REQUIRE_MSG(list.d != NULL, "pkgvec_push failed");
-
	ATF_REQUIRE_EQ_MSG(list.cap, 1, "pkgvec_push failed");
-
	ATF_REQUIRE_EQ_MSG(list.len, 1, "pkgvec_push failed");
-

-
	pkgvec_push(&list, "test2");
-
	ATF_REQUIRE_MSG(list.d != NULL, "pkgvec_push2 failed");
-
	ATF_REQUIRE_EQ_MSG(list.cap, 2, "pkgvec_push2 failed");
-
	ATF_REQUIRE_EQ_MSG(list.len, 2, "pkgvec_push2 failed");
-

-
	pkgvec_push(&list, "test3");
-
	ATF_REQUIRE_MSG(list.d != NULL, "pkgvec_push3 failed");
-
	ATF_REQUIRE_EQ_MSG(list.cap, 4, "pkgvec_push3 failed");
-
	ATF_REQUIRE_EQ_MSG(list.len, 3, "pkgvec_push3 failed");
-

-
	ATF_REQUIRE_STREQ_MSG(pkgvec_first(&list), "test1", "pkgvec_first failed");
-
	ATF_REQUIRE_STREQ_MSG(pkgvec_last(&list), "test3", "pkgvec_last failed");
-

-
	pkgvec_clear(&list);
-
	ATF_REQUIRE_MSG(list.d != NULL, "pkgvec_clear failed");
-
	ATF_REQUIRE_EQ_MSG(list.cap, 4, "pkgvec_clear failed");
-
	ATF_REQUIRE_EQ_MSG(list.len, 0, "pkgvec_clear failed");
-

-
	pkgvec_free(&list);
-
	ATF_REQUIRE_EQ_MSG(list.d, NULL, "pkgvec_free failed");
-
	ATF_REQUIRE_EQ_MSG(list.cap, 0, "pkgvec_free failed");
-
	ATF_REQUIRE_EQ_MSG(list.len, 0, "pkgvec_free failed");
+
	vec_init(&list);
+
	ATF_REQUIRE_EQ_MSG(list.d, NULL, "vec_init failed");
+
	ATF_REQUIRE_EQ_MSG(list.cap, 0, "vec_init failed");
+
	ATF_REQUIRE_EQ_MSG(list.len, 0, "vec_init failed");
+

+
	vec_push(&list, "test1");
+
	ATF_REQUIRE_MSG(list.d != NULL, "vec_push failed");
+
	ATF_REQUIRE_EQ_MSG(list.cap, 1, "vec_push failed");
+
	ATF_REQUIRE_EQ_MSG(list.len, 1, "vec_push failed");
+

+
	vec_push(&list, "test2");
+
	ATF_REQUIRE_MSG(list.d != NULL, "vec_push2 failed");
+
	ATF_REQUIRE_EQ_MSG(list.cap, 2, "vec_push2 failed");
+
	ATF_REQUIRE_EQ_MSG(list.len, 2, "vec_push2 failed");
+

+
	vec_push(&list, "test3");
+
	ATF_REQUIRE_MSG(list.d != NULL, "vec_push3 failed");
+
	ATF_REQUIRE_EQ_MSG(list.cap, 4, "vec_push3 failed");
+
	ATF_REQUIRE_EQ_MSG(list.len, 3, "vec_push3 failed");
+

+
	ATF_REQUIRE_STREQ_MSG(vec_first(&list), "test1", "vec_first failed");
+
	ATF_REQUIRE_STREQ_MSG(vec_last(&list), "test3", "vec_last failed");
+

+
	vec_clear(&list);
+
	ATF_REQUIRE_MSG(list.d != NULL, "vec_clear failed");
+
	ATF_REQUIRE_EQ_MSG(list.cap, 4, "vec_clear failed");
+
	ATF_REQUIRE_EQ_MSG(list.len, 0, "vec_clear failed");
+

+
	vec_free(&list);
+
	ATF_REQUIRE_EQ_MSG(list.d, NULL, "vec_free failed");
+
	ATF_REQUIRE_EQ_MSG(list.cap, 0, "vec_free failed");
+
	ATF_REQUIRE_EQ_MSG(list.len, 0, "vec_free failed");
}

ATF_TC_BODY(charv_t, tc)
{
	charv_t list;

-
	pkgvec_init(&list);
-
	ATF_REQUIRE_EQ_MSG(list.d, NULL, "pkgvec_init failed");
-
	ATF_REQUIRE_EQ_MSG(list.cap, 0, "pkgvec_init failed");
-
	ATF_REQUIRE_EQ_MSG(list.len, 0, "pkgvec_init failed");
-

-
	pkgvec_push(&list, xstrdup("test1"));
-
	ATF_REQUIRE_MSG(list.d != NULL, "pkgvec_push failed");
-
	ATF_REQUIRE_EQ_MSG(list.cap, 1, "pkgvec_push failed");
-
	ATF_REQUIRE_EQ_MSG(list.len, 1, "pkgvec_push failed");
-

-
	pkgvec_push(&list, xstrdup("test2"));
-
	ATF_REQUIRE_MSG(list.d != NULL, "pkgvec_push2 failed");
-
	ATF_REQUIRE_EQ_MSG(list.cap, 2, "pkgvec_push2 failed");
-
	ATF_REQUIRE_EQ_MSG(list.len, 2, "pkgvec_push2 failed");
-

-
	pkgvec_push(&list, xstrdup("test3"));
-
	ATF_REQUIRE_MSG(list.d != NULL, "pkgvec_push3 failed");
-
	ATF_REQUIRE_EQ_MSG(list.cap, 4, "pkgvec_push3 failed");
-
	ATF_REQUIRE_EQ_MSG(list.len, 3, "pkgvec_push3 failed");
-

-
	ATF_REQUIRE_STREQ_MSG(pkgvec_first(&list), "test1", "pkgvec_first failed");
-
	ATF_REQUIRE_STREQ_MSG(pkgvec_last(&list), "test3", "pkgvec_last failed");
-

-
	pkgvec_clear_and_free(&list, free);
-
	ATF_REQUIRE_MSG(list.d != NULL, "pkgvec_clear failed");
-
	ATF_REQUIRE_EQ_MSG(list.cap, 4, "pkgvec_clear failed");
-
	ATF_REQUIRE_EQ_MSG(list.len, 0, "pkgvec_clear failed");
-

-
	pkgvec_free_and_free(&list, free);
-
	ATF_REQUIRE_EQ_MSG(list.d, NULL, "pkgvec_free failed");
-
	ATF_REQUIRE_EQ_MSG(list.cap, 0, "pkgvec_free failed");
-
	ATF_REQUIRE_EQ_MSG(list.len, 0, "pkgvec_free failed");
+
	vec_init(&list);
+
	ATF_REQUIRE_EQ_MSG(list.d, NULL, "vec_init failed");
+
	ATF_REQUIRE_EQ_MSG(list.cap, 0, "vec_init failed");
+
	ATF_REQUIRE_EQ_MSG(list.len, 0, "vec_init failed");
+

+
	vec_push(&list, xstrdup("test1"));
+
	ATF_REQUIRE_MSG(list.d != NULL, "vec_push failed");
+
	ATF_REQUIRE_EQ_MSG(list.cap, 1, "vec_push failed");
+
	ATF_REQUIRE_EQ_MSG(list.len, 1, "vec_push failed");
+

+
	vec_push(&list, xstrdup("test2"));
+
	ATF_REQUIRE_MSG(list.d != NULL, "vec_push2 failed");
+
	ATF_REQUIRE_EQ_MSG(list.cap, 2, "vec_push2 failed");
+
	ATF_REQUIRE_EQ_MSG(list.len, 2, "vec_push2 failed");
+

+
	vec_push(&list, xstrdup("test3"));
+
	ATF_REQUIRE_MSG(list.d != NULL, "vec_push3 failed");
+
	ATF_REQUIRE_EQ_MSG(list.cap, 4, "vec_push3 failed");
+
	ATF_REQUIRE_EQ_MSG(list.len, 3, "vec_push3 failed");
+

+
	ATF_REQUIRE_STREQ_MSG(vec_first(&list), "test1", "vec_first failed");
+
	ATF_REQUIRE_STREQ_MSG(vec_last(&list), "test3", "vec_last failed");
+

+
	vec_clear_and_free(&list, free);
+
	ATF_REQUIRE_MSG(list.d != NULL, "vec_clear failed");
+
	ATF_REQUIRE_EQ_MSG(list.cap, 4, "vec_clear failed");
+
	ATF_REQUIRE_EQ_MSG(list.len, 0, "vec_clear failed");
+

+
	vec_free_and_free(&list, free);
+
	ATF_REQUIRE_EQ_MSG(list.d, NULL, "vec_free failed");
+
	ATF_REQUIRE_EQ_MSG(list.cap, 0, "vec_free failed");
+
	ATF_REQUIRE_EQ_MSG(list.len, 0, "vec_free failed");
}

ATF_TC_BODY(c_charv_contains, tc)
{
	c_charv_t list;

-
	pkgvec_init(&list);
-
	ATF_REQUIRE_EQ_MSG(list.d, NULL, "pkgvec_init failed");
-
	ATF_REQUIRE_EQ_MSG(list.cap, 0, "pkgvec_init failed");
-
	ATF_REQUIRE_EQ_MSG(list.len, 0, "pkgvec_init failed");
+
	vec_init(&list);
+
	ATF_REQUIRE_EQ_MSG(list.d, NULL, "vec_init failed");
+
	ATF_REQUIRE_EQ_MSG(list.cap, 0, "vec_init failed");
+
	ATF_REQUIRE_EQ_MSG(list.len, 0, "vec_init failed");

-
	pkgvec_push(&list, "test1");
-
	ATF_REQUIRE_MSG(list.d != NULL, "pkgvec_push failed");
-
	ATF_REQUIRE_EQ_MSG(list.cap, 1, "pkgvec_push failed");
-
	ATF_REQUIRE_EQ_MSG(list.len, 1, "pkgvec_push failed");
+
	vec_push(&list, "test1");
+
	ATF_REQUIRE_MSG(list.d != NULL, "vec_push failed");
+
	ATF_REQUIRE_EQ_MSG(list.cap, 1, "vec_push failed");
+
	ATF_REQUIRE_EQ_MSG(list.len, 1, "vec_push failed");

-
	pkgvec_push(&list, "test2");
-
	ATF_REQUIRE_MSG(list.d != NULL, "pkgvec_push2 failed");
-
	ATF_REQUIRE_EQ_MSG(list.cap, 2, "pkgvec_push2 failed");
-
	ATF_REQUIRE_EQ_MSG(list.len, 2, "pkgvec_push2 failed");
+
	vec_push(&list, "test2");
+
	ATF_REQUIRE_MSG(list.d != NULL, "vec_push2 failed");
+
	ATF_REQUIRE_EQ_MSG(list.cap, 2, "vec_push2 failed");
+
	ATF_REQUIRE_EQ_MSG(list.len, 2, "vec_push2 failed");

-
	pkgvec_push(&list, "test3");
-
	ATF_REQUIRE_MSG(list.d != NULL, "pkgvec_push3 failed");
-
	ATF_REQUIRE_EQ_MSG(list.cap, 4, "pkgvec_push3 failed");
-
	ATF_REQUIRE_EQ_MSG(list.len, 3, "pkgvec_push3 failed");
+
	vec_push(&list, "test3");
+
	ATF_REQUIRE_MSG(list.d != NULL, "vec_push3 failed");
+
	ATF_REQUIRE_EQ_MSG(list.cap, 4, "vec_push3 failed");
+
	ATF_REQUIRE_EQ_MSG(list.len, 3, "vec_push3 failed");

	ATF_REQUIRE_EQ_MSG(c_charv_contains(&list, "Test3", true), false, "c_charv_contains not case sensitive");
	ATF_REQUIRE_EQ_MSG(c_charv_contains(&list, "Test3", false), true, "c_charv_contains not case insensitive");
	ATF_REQUIRE_EQ_MSG(c_charv_contains(&list, "aest3", false), false, "c_charv_contains should not find anything");

-
	pkgvec_free(&list);
+
	vec_free(&list);
}

ATF_TP_ADD_TCS(tp)