public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2014-03-08  5:51 Mike Frysinger
  0 siblings, 0 replies; 23+ messages in thread
From: Mike Frysinger @ 2014-03-08  5:51 UTC (permalink / raw
  To: gentoo-commits

commit:     8a2857f3ced8f191b56a3e690cacf03a3a745d67
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 16 21:14:24 2014 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sun Feb 16 21:14:24 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage-utils.git;a=commit;h=8a2857f3

start using O_PATH

---
 TODO             |  3 +--
 libq/profile.c   |  2 +-
 libq/scandirat.c |  3 ++-
 libq/vdb.c       | 12 ++++++++----
 libq/xmkdir.c    |  1 +
 porting.h        |  5 ++++-
 qmerge.c         | 13 +++++++------
 qtbz2.c          |  6 +++---
 qxpak.c          |  6 +++---
 9 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/TODO b/TODO
index 5f1f382..4bb86fb 100644
--- a/TODO
+++ b/TODO
@@ -11,8 +11,6 @@
 
 - speed up queue structure ... append walks the whole list
 
-- use O_PATH with fd's that are only used to open other files
-
 - qmerge
 	- dep resolver needs spanktastic love.
 	- needs safe deleting (merge in place rather than unmerge;merge)
@@ -35,6 +33,7 @@
 		foo-(1234)_alpha(56789)
 	- these limits should not be an issue for all practical purposes
 	- need to handle USE deps like: cat/pkg-123[foo(+)]
+	- show support slots like: qmerge -U automake:1.12
 
 - qcache:
 	- need to convert it to new metadata/md5 style

diff --git a/libq/profile.c b/libq/profile.c
index 707695d..75f3cb0 100644
--- a/libq/profile.c
+++ b/libq/profile.c
@@ -10,7 +10,7 @@ q_profile_walk_at(int dir_fd, const char *dir, const char *file,
 	char *buf;
 
 	/* Pop open this profile dir */
-	subdir_fd = openat(dir_fd, dir, O_RDONLY|O_CLOEXEC);
+	subdir_fd = openat(dir_fd, dir, O_RDONLY|O_CLOEXEC|O_PATH);
 	if (subdir_fd < 0)
 		return data;
 

diff --git a/libq/scandirat.c b/libq/scandirat.c
index 76a5d4a..0a84828 100644
--- a/libq/scandirat.c
+++ b/libq/scandirat.c
@@ -1,7 +1,7 @@
 /*
  * Copyright 2005-2011 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/scandirat.c,v 1.7 2013/11/17 10:26:53 grobian Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/scandirat.c,v 1.8 2014/02/16 21:14:24 vapier Exp $
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2011 Mike Frysinger  - <vapier@gentoo.org>
@@ -29,6 +29,7 @@ static int scandirat(int dir_fd, const char *dir, struct dirent ***dirlist,
 	DIR *dirp;
 	struct dirent *de, **ret;
 
+	/* Cannot use O_PATH as we want to use fdopendir() */
 	fd = openat(dir_fd, dir, O_RDONLY|O_CLOEXEC);
 	if (fd == -1)
 		return -1;

diff --git a/libq/vdb.c b/libq/vdb.c
index 156e088..1100405 100644
--- a/libq/vdb.c
+++ b/libq/vdb.c
@@ -1,7 +1,7 @@
 /*
  * Copyright 2005-2011 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/vdb.c,v 1.5 2012/10/28 06:27:59 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/vdb.c,v 1.6 2014/02/16 21:14:24 vapier Exp $
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2011 Mike Frysinger  - <vapier@gentoo.org>
@@ -24,7 +24,7 @@ _q_static q_vdb_ctx *q_vdb_open(/*const char *sroot, const char *svdb*/void)
 
 	if (!sroot)
 		sroot = portroot;
-	ctx->portroot_fd = open(sroot, O_RDONLY|O_CLOEXEC);
+	ctx->portroot_fd = open(sroot, O_RDONLY|O_CLOEXEC|O_PATH);
 	if (ctx->portroot_fd == -1) {
 		warnp("could not open root: %s", sroot);
 		goto f_error;
@@ -36,6 +36,7 @@ _q_static q_vdb_ctx *q_vdb_open(/*const char *sroot, const char *svdb*/void)
 	svdb++;
 	if (*svdb == '\0')
 		svdb = ".";
+	/* Cannot use O_PATH as we want to use fdopendir() */
 	ctx->vdb_fd = openat(ctx->portroot_fd, svdb, O_RDONLY|O_CLOEXEC);
 	if (ctx->vdb_fd == -1) {
 		warnp("could not open vdb: %s (in root %s)", svdb, sroot);
@@ -114,6 +115,7 @@ _q_static q_vdb_cat_ctx *q_vdb_open_cat(q_vdb_ctx *ctx, const char *name)
 	int fd;
 	DIR *dir;
 
+	/* Cannot use O_PATH as we want to use fdopendir() */
 	fd = openat(ctx->vdb_fd, name, O_RDONLY|O_CLOEXEC);
 	if (fd == -1)
 		return NULL;
@@ -194,9 +196,10 @@ _q_static q_vdb_pkg_ctx *q_vdb_open_pkg(q_vdb_cat_ctx *cat_ctx, const char *name
 	q_vdb_pkg_ctx *pkg_ctx;
 	int fd;
 
-	fd = openat(cat_ctx->fd, name, O_RDONLY|O_CLOEXEC);
+//	fd = openat(cat_ctx->fd, name, O_RDONLY|O_CLOEXEC|O_PATH);
 	if (fd == -1)
 		return NULL;
+	fd = -1;
 
 	pkg_ctx = xmalloc(sizeof(*pkg_ctx));
 	pkg_ctx->name = name;
@@ -251,7 +254,8 @@ _q_static FILE *q_vdb_pkg_fopenat(q_vdb_pkg_ctx *pkg_ctx, const char *file,
 
 _q_static void q_vdb_close_pkg(q_vdb_pkg_ctx *pkg_ctx)
 {
-	close(pkg_ctx->fd);
+	if (pkg_ctx->fd != -1)
+		close(pkg_ctx->fd);
 	free(pkg_ctx);
 }
 

diff --git a/libq/xmkdir.c b/libq/xmkdir.c
index eb0123a..600e6d0 100644
--- a/libq/xmkdir.c
+++ b/libq/xmkdir.c
@@ -43,6 +43,7 @@ _q_static int rm_rf_at(int dfd, const char *path)
 	DIR *dir;
 	struct dirent *de;
 
+	/* Cannot use O_PATH as we want to use fdopendir() */
 	subdfd = openat(dfd, path, O_RDONLY|O_CLOEXEC|O_NOFOLLOW);
 	if (subdfd < 0)
 		return -1;

diff --git a/porting.h b/porting.h
index 8c93f05..f36d6b7 100644
--- a/porting.h
+++ b/porting.h
@@ -1,7 +1,7 @@
 /*
  * Copyright 2005-2013 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/porting.h,v 1.1 2013/09/29 22:42:36 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/porting.h,v 1.2 2014/02/16 21:14:24 vapier Exp $
  *
  * Copyright 2005-2008 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2013 Mike Frysinger  - <vapier@gentoo.org>
@@ -66,6 +66,9 @@
 #ifndef O_CLOEXEC
 #define O_CLOEXEC 0
 #endif
+#ifndef O_PATH
+#define O_PATH 0
+#endif
 
 #ifndef CONFIG_EPREFIX
 #define CONFIG_EPREFIX "/"

diff --git a/qmerge.c b/qmerge.c
index 40d4139..5ec9be8 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -1,7 +1,7 @@
 /*
  * Copyright 2005-2010 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qmerge.c,v 1.131 2014/01/07 19:17:25 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qmerge.c,v 1.132 2014/02/16 21:14:24 vapier Exp $
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2010 Mike Frysinger  - <vapier@gentoo.org>
@@ -65,7 +65,7 @@ static const char * const qmerge_opts_help[] = {
 	COMMON_OPTS_HELP
 };
 
-static const char qmerge_rcsid[] = "$Id: qmerge.c,v 1.131 2014/01/07 19:17:25 vapier Exp $";
+static const char qmerge_rcsid[] = "$Id: qmerge.c,v 1.132 2014/02/16 21:14:24 vapier Exp $";
 #define qmerge_usage(ret) usage(ret, QMERGE_FLAGS, qmerge_long_opts, qmerge_opts_help, lookup_applet_idx("qmerge"))
 
 char search_pkgs = 0;
@@ -237,7 +237,7 @@ _q_static char *best_version(const char *catname, const char *pkgname)
 	/* Make sure these dirs exist before we try walking them */
 	switch (vdb_check) {
 	case 1: {
-		int fd = open(portroot, O_RDONLY|O_CLOEXEC);
+		int fd = open(portroot, O_RDONLY|O_CLOEXEC|O_PATH);
 		if (fd >= 0) {
 			/* skip leading slash */
 			vdb_check = faccessat(fd, portvdb + 1, X_OK, 0);
@@ -483,10 +483,11 @@ merge_tree_at(int fd_src, const char *src, int fd_dst, const char *dst,
 	ret = -1;
 
 	/* Get handles to these subdirs */
+	/* Cannot use O_PATH as we want to use fdopendir() */
 	subfd_src = openat(fd_src, src, O_RDONLY|O_CLOEXEC);
 	if (subfd_src < 0)
 		return ret;
-	subfd_dst = openat(fd_dst, dst, O_RDONLY|O_CLOEXEC);
+	subfd_dst = openat(fd_dst, dst, O_RDONLY|O_CLOEXEC|O_PATH);
 	if (subfd_dst < 0) {
 		close(subfd_src);
 		return ret;
@@ -1038,7 +1039,7 @@ pkg_unmerge(const char *cat, const char *pkgname, queue *keep)
 		return 0;
 
 	/* Get a handle to the root to play with */
-	portroot_fd = open(portroot, O_RDONLY | O_CLOEXEC);
+	portroot_fd = open(portroot, O_RDONLY|O_CLOEXEC|O_PATH);
 	if (portroot_fd == -1) {
 		warnp("unable to read %s", portroot);
 		goto done;
@@ -1048,7 +1049,7 @@ pkg_unmerge(const char *cat, const char *pkgname, queue *keep)
 	/* Note: This vdb_path must be absolute since we use it in pkg_run_func() */
 	xasprintf(&vdb_path, "%s%s/%s/%s/", portroot, portvdb, cat, pkgname);
 	xasprintf(&T, "%stemp", vdb_path);
-	vdb_fd = openat(portroot_fd, vdb_path, O_RDONLY | O_CLOEXEC);
+	vdb_fd = openat(portroot_fd, vdb_path, O_RDONLY|O_CLOEXEC|O_PATH);
 	if (vdb_fd == -1) {
 		warnp("unable to read %s", vdb_path);
 		goto done;

diff --git a/qtbz2.c b/qtbz2.c
index 24d75bf..4f9f24c 100644
--- a/qtbz2.c
+++ b/qtbz2.c
@@ -1,7 +1,7 @@
 /*
  * Copyright 2005-2010 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qtbz2.c,v 1.21 2012/11/17 18:44:58 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qtbz2.c,v 1.22 2014/02/16 21:14:24 vapier Exp $
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2010 Mike Frysinger  - <vapier@gentoo.org>
@@ -46,7 +46,7 @@ static const char * const qtbz2_opts_help[] = {
 	"Write files to stdout",
 	COMMON_OPTS_HELP
 };
-static const char qtbz2_rcsid[] = "$Id: qtbz2.c,v 1.21 2012/11/17 18:44:58 vapier Exp $";
+static const char qtbz2_rcsid[] = "$Id: qtbz2.c,v 1.22 2014/02/16 21:14:24 vapier Exp $";
 #define qtbz2_usage(ret) usage(ret, QTBZ2_FLAGS, qtbz2_long_opts, qtbz2_opts_help, lookup_applet_idx("qtbz2"))
 
 static char tbz2_stdout = 0;
@@ -263,7 +263,7 @@ int qtbz2_main(int argc, char **argv)
 		case 'd':
 			if (dir_fd != AT_FDCWD)
 				err("Only use -d once");
-			dir_fd = open(optarg, O_RDONLY|O_CLOEXEC);
+			dir_fd = open(optarg, O_RDONLY|O_CLOEXEC|O_PATH);
 			break;
 		}
 	}

diff --git a/qxpak.c b/qxpak.c
index 989dc97..2d1a7ad 100644
--- a/qxpak.c
+++ b/qxpak.c
@@ -1,7 +1,7 @@
 /*
  * Copyright 2005-2010 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qxpak.c,v 1.26 2013/04/21 04:28:10 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qxpak.c,v 1.27 2014/02/16 21:14:24 vapier Exp $
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2010 Mike Frysinger  - <vapier@gentoo.org>
@@ -46,7 +46,7 @@ static const char * const qxpak_opts_help[] = {
 	"Write files to stdout",
 	COMMON_OPTS_HELP
 };
-static const char qxpak_rcsid[] = "$Id: qxpak.c,v 1.26 2013/04/21 04:28:10 vapier Exp $";
+static const char qxpak_rcsid[] = "$Id: qxpak.c,v 1.27 2014/02/16 21:14:24 vapier Exp $";
 #define qxpak_usage(ret) usage(ret, QXPAK_FLAGS, qxpak_long_opts, qxpak_opts_help, lookup_applet_idx("qxpak"))
 
 typedef struct {
@@ -397,7 +397,7 @@ int qxpak_main(int argc, char **argv)
 		case 'd':
 			if (dir_fd != AT_FDCWD)
 				err("Only use -d once");
-			dir_fd = open(optarg, O_RDONLY|O_CLOEXEC);
+			dir_fd = open(optarg, O_RDONLY|O_CLOEXEC|O_PATH);
 			break;
 		}
 	}


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2014-03-08  5:51 Mike Frysinger
  0 siblings, 0 replies; 23+ messages in thread
From: Mike Frysinger @ 2014-03-08  5:51 UTC (permalink / raw
  To: gentoo-commits

commit:     e2af8a0e5a7d0e055e3007dd750d5754d952a71d
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Tue Feb 18 07:26:13 2014 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Tue Feb 18 07:26:13 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage-utils.git;a=commit;h=e2af8a0e

drop support for old style virtuals as the tree has not carried them in a long time

---
 libq/virtuals.c | 128 +-------------------------------------------------------
 main.c          |   3 +-
 qdepends.c      |  12 +-----
 qmerge.c        |  21 ++--------
 4 files changed, 9 insertions(+), 155 deletions(-)

diff --git a/libq/virtuals.c b/libq/virtuals.c
index 39df3b5..d4f4ae7 100644
--- a/libq/virtuals.c
+++ b/libq/virtuals.c
@@ -1,12 +1,12 @@
 /*
  * Copyright 2005-2010 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/virtuals.c,v 1.27 2011/12/18 20:41:54 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/virtuals.c,v 1.28 2014/02/18 07:26:13 vapier Exp $
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2010 Mike Frysinger  - <vapier@gentoo.org>
  *
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/virtuals.c,v 1.27 2011/12/18 20:41:54 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/virtuals.c,v 1.28 2014/02/18 07:26:13 vapier Exp $
  */
 
 #include <stdio.h>
@@ -23,14 +23,9 @@ struct queue_t {
 
 typedef struct queue_t queue;
 
-/* global */
-queue *virtuals = NULL;
-
 queue *del_set(char *s, queue *q, int *ok);
 queue *add_set(const char *vv, const char *ss, queue *q);
 
-/* void free_virtuals(queue *list); */
-
 static queue *append_set(queue *q, queue *ll)
 {
 	queue *z;
@@ -156,122 +151,3 @@ void print_sets(queue *list)
 	for (ll = list; ll != NULL; ll = ll->next)
 		printf("%s -> %s\n", ll->name, ll->item);
 }
-
-queue *resolve_vdb_virtuals(char *vdb);
-queue *resolve_vdb_virtuals(char *vdb)
-{
-	DIR *dir, *dirp;
-	struct dirent *dentry_cat, *dentry_pkg;
-	char buf[_Q_PATH_MAX];
-	depend_atom *atom;
-
-	xchdir("/");
-
-	/* now try to run through vdb and locate matches for user inputs */
-	if ((dir = opendir(vdb)) == NULL)
-		return virtuals;
-
-	/* scan all the categories */
-	while ((dentry_cat = q_vdb_get_next_dir(dir)) != NULL) {
-		snprintf(buf, sizeof(buf), "%s/%s", vdb, dentry_cat->d_name);
-		if ((dirp = opendir(buf)) == NULL)
-			continue;
-
-		/* scan all the packages in this category */
-		while ((dentry_pkg = q_vdb_get_next_dir(dirp)) != NULL) {
-			char *p;
-			/* see if user wants any of these packages */
-			snprintf(buf, sizeof(buf), "%s/%s/%s/PROVIDE", vdb, dentry_cat->d_name, dentry_pkg->d_name);
-
-			if (!eat_file(buf, buf, sizeof(buf)))
-				continue;
-
-			if ((p = strrchr(buf, '\n')) != NULL)
-				*p = 0;
-
-			rmspace(buf);
-
-			if (*buf) {
-				int ok = 0;
-				char *v, *tmp = xstrdup(buf);
-				snprintf(buf, sizeof(buf), "%s/%s", dentry_cat->d_name, dentry_pkg->d_name);
-
-				atom = atom_explode(buf);
-				if (!atom) {
-					warn("could not explode '%s'", buf);
-					continue;
-				}
-				sprintf(buf, "%s/%s", atom->CATEGORY, atom->PN);
-				if ((v = virtual(tmp, virtuals)) != NULL) {
-					/* IF_DEBUG(fprintf(stderr, "%s provided by %s (removing)\n", tmp, v)); */
-					virtuals = del_set(tmp,  virtuals, &ok);
-				}
-				virtuals = add_set(tmp, buf, virtuals);
-				/* IF_DEBUG(fprintf(stderr, "%s provided by %s/%s (adding)\n", tmp, atom->CATEGORY, dentry_pkg->d_name)); */
-				free(tmp);
-				atom_implode(atom);
-			}
-		}
-	}
-
-	return virtuals;
-}
-
-static queue *resolve_local_profile_virtuals(void)
-{
-	static size_t buflen;
-	static char *buf = NULL;
-	FILE *fp;
-	char *p;
-	static const char * const paths[] = { "/etc/portage/profile/virtuals", "/etc/portage/virtuals" };
-	size_t i;
-
-	for (i = 0; i < ARRAY_SIZE(paths); ++i) {
-		fp = fopen(paths[i], "r");
-		if (!fp)
-			continue;
-
-		while (getline(&buf, &buflen, fp) != -1) {
-			if (*buf != 'v')
-				continue;
-			rmspace(buf);
-			if ((p = strchr(buf, ' ')) != NULL) {
-				int ok = 0;
-				*p = 0;
-				virtuals = del_set(buf, virtuals, &ok);
-				virtuals = add_set(buf, rmspace(++p), virtuals);
-				ok = 0;
-			}
-		}
-
-		fclose(fp);
-	}
-
-	return virtuals;
-}
-
-_q_static void *
-resolve_virtuals_line(void *data, char *buf)
-{
-	char *p;
-
-	if (*buf != 'v')
-		return data;
-
-	rmspace(buf);
-	if ((p = strchr(buf, ' ')) != NULL) {
-		*p = 0;
-		if (virtual(buf, virtuals) == NULL)
-			virtuals = add_set(buf, rmspace(++p), virtuals);
-	}
-
-	return data;
-}
-
-_q_static queue *resolve_virtuals(void)
-{
-	free_sets(virtuals);
-	virtuals = resolve_local_profile_virtuals();
-	virtuals = resolve_vdb_virtuals(portvdb);
-	return q_profile_walk("virtuals", resolve_virtuals_line, virtuals);
-}

diff --git a/main.c b/main.c
index f982cfa..e87dbee 100644
--- a/main.c
+++ b/main.c
@@ -1,7 +1,7 @@
 /*
  * Copyright 2005-2013 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/main.c,v 1.229 2013/10/31 02:40:23 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/main.c,v 1.230 2014/02/18 07:26:14 vapier Exp $
  *
  * Copyright 2005-2008 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2013 Mike Frysinger  - <vapier@gentoo.org>
@@ -1278,7 +1278,6 @@ _q_static queue *get_vdb_atoms(int fullcpv)
 void cleanup(void)
 {
 	reinitialize_as_needed();
-	free_sets(virtuals);
 	fclose(stderr);
 }
 

diff --git a/qdepends.c b/qdepends.c
index dad3f02..b6c0d1c 100644
--- a/qdepends.c
+++ b/qdepends.c
@@ -1,7 +1,7 @@
 /*
  * Copyright 2005-2013 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qdepends.c,v 1.66 2013/09/29 22:19:39 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qdepends.c,v 1.67 2014/02/18 07:26:14 vapier Exp $
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2013 Mike Frysinger  - <vapier@gentoo.org>
@@ -32,7 +32,7 @@ static const char * const qdepends_opts_help[] = {
 	"Pretty format specified depend strings",
 	COMMON_OPTS_HELP
 };
-static const char qdepends_rcsid[] = "$Id: qdepends.c,v 1.66 2013/09/29 22:19:39 vapier Exp $";
+static const char qdepends_rcsid[] = "$Id: qdepends.c,v 1.67 2014/02/18 07:26:14 vapier Exp $";
 #define qdepends_usage(ret) usage(ret, QDEPENDS_FLAGS, qdepends_long_opts, qdepends_opts_help, lookup_applet_idx("qdepends"))
 
 static char qdep_name_only = 0;
@@ -358,14 +358,6 @@ void _dep_flatten_tree(const dep_node *root, char *buf, size_t *pos)
 	if (root->type == DEP_NULL) goto this_node_sucks;
 	if (root->type == DEP_NORM) {
 		size_t len = strlen(root->info);
-#if 1
-		if (*root->info == 'v')
-			if (strncmp(root->info, "virtual/", 8) == 0) {
-				if (virtuals == NULL)
-					virtuals = resolve_virtuals();
-				IF_DEBUG(fprintf(stderr, "(%s->%s)", root->info, virtual(root->info, virtuals)));
-			}
-#endif
 		memcpy(buf + *pos, root->info, len);
 		*pos += len+1;
 		buf[*pos-1] = ' ';

diff --git a/qmerge.c b/qmerge.c
index 1a44e46..8d77b7e 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -1,7 +1,7 @@
 /*
  * Copyright 2005-2010 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qmerge.c,v 1.138 2014/02/18 06:59:05 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qmerge.c,v 1.139 2014/02/18 07:26:14 vapier Exp $
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2010 Mike Frysinger  - <vapier@gentoo.org>
@@ -67,7 +67,7 @@ static const char * const qmerge_opts_help[] = {
 	COMMON_OPTS_HELP
 };
 
-static const char qmerge_rcsid[] = "$Id: qmerge.c,v 1.138 2014/02/18 06:59:05 vapier Exp $";
+static const char qmerge_rcsid[] = "$Id: qmerge.c,v 1.139 2014/02/18 07:26:14 vapier Exp $";
 #define qmerge_usage(ret) usage(ret, QMERGE_FLAGS, qmerge_long_opts, qmerge_opts_help, lookup_applet_idx("qmerge"))
 
 char search_pkgs = 0;
@@ -814,25 +814,12 @@ pkg_merge(int level, const depend_atom *atom, const struct pkg_t *pkg)
 						/* warn("newname = %s", name); */
 					}
 					if ((subatom = atom_explode(name)) != NULL) {
-						char *dep;
 						struct pkg_t *subpkg;
 						char *resolved = NULL;
 
-						dep = find_binpkg(name);
+						resolved = find_binpkg(name);
 
-						if (strncmp(name, "virtual/", 8) == 0) {
-							if (virtuals == NULL)
-								virtuals = resolve_virtuals();
-							resolved = find_binpkg(virtual(name, virtuals));
-							if (resolved == NULL || !strlen(resolved))
-								resolved = find_binpkg(name);
-						} else
-							resolved = NULL;
-
-						if (resolved == NULL)
-							resolved = dep;
-
-						IF_DEBUG(fprintf(stderr, "+Atom: argv0(%s) dep(%s) resolved(%s)\n", name, dep, resolved));
+						IF_DEBUG(fprintf(stderr, "+Atom: argv0(%s) resolved(%s)\n", name, resolved));
 
 						if (strlen(resolved) < 1) {
 							warn("Cant find a binpkg for %s from rdepend(%s)", name, pkg->RDEPEND);


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2014-03-10  6:00 Mike Frysinger
  0 siblings, 0 replies; 23+ messages in thread
From: Mike Frysinger @ 2014-03-10  6:00 UTC (permalink / raw
  To: gentoo-commits

commit:     a235b67877128a5ab23388cabb0a31bf3502094e
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sun Mar  9 21:07:24 2014 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sun Mar  9 21:07:24 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage-utils.git;a=commit;h=a235b678

use localized number formats

NLS becomes a proper compile time option and we use that to print numbers
in a more natural format.

If people want raw format for scripts, you can set LC_ALL=C.

URL: https://bugs.gentoo.org/503646

---
 Makefile              |  2 ++
 libq/human_readable.c |  6 +++---
 libq/i18n.h           |  4 +++-
 main.c                |  3 +--
 qmerge.c              |  2 +-
 qsize.c               | 18 ++++++++++--------
 6 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/Makefile b/Makefile
index 2889fe2..d202f54 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,7 @@
 
 check_gcc=$(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
 	then echo "$(1)"; else echo "$(2)"; fi)
+istrue = $(if $(filter 1 yes true on,$(strip $1)),1,0)
 
 ####################################################
 WFLAGS    := -Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \
@@ -18,6 +19,7 @@ WFLAGS    := -Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \
 CFLAGS    ?= -O2 -g -pipe
 CFLAGS    += -std=gnu99
 CPPFLAGS  ?=
+CPPFLAGS  += -DENABLE_NLS=$(call istrue,$(NLS))
 #CFLAGS   += -DEBUG -g
 #CFLAGS   += -Os -DOPTIMIZE_FOR_SIZE=2 -falign-functions=2 -falign-jumps=2 -falign-labels=2 -falign-loops=2
 #LDFLAGS  := -pie

diff --git a/libq/human_readable.c b/libq/human_readable.c
index bdef428..3a8aa34 100644
--- a/libq/human_readable.c
+++ b/libq/human_readable.c
@@ -38,8 +38,8 @@ const char *make_human_readable_str(unsigned long long size,
 {
 	/* The code will adjust for additional (appended) units. */
 	static const char zero_and_units[] = { '0', 0, 'k', 'M', 'G', 'T' };
-	static const char fmt[] = "%Lu";
-	static const char fmt_tenths[] = "%Lu.%d%c";
+	static const char fmt[] = "%'Lu";
+	static const char fmt_tenths[] = "%'Lu%s%d%c";
 
 	static char str[21];		/* Sufficient for 64 bit unsigned integers. */
 
@@ -85,7 +85,7 @@ const char *make_human_readable_str(unsigned long long size,
 	}
 
 	/* If f==fmt then 'frac' and 'u' are ignored. */
-	snprintf(str, sizeof(str), f, val, frac, *u);
+	snprintf(str, sizeof(str), f, val, decimal_point, frac, *u);
 
 	return str;
 }

diff --git a/libq/i18n.h b/libq/i18n.h
index d26713c..50f36ea 100644
--- a/libq/i18n.h
+++ b/libq/i18n.h
@@ -1,15 +1,17 @@
 #ifndef _I18N_H
 #define _I18N_H
 
-#ifdef ENABLE_NLS
+#if ENABLE_NLS
 # include <locale.h>
 # include <libintl.h>
 # define _(String) gettext (String)
+# define decimal_point localeconv()->decimal_point
 #else
 # define _(String) (String)
 # define setlocale(x,y)
 # define bindtextdomain(x,y)
 # define textdomain(x)
+# define decimal_point "."
 #endif
 
 #endif

diff --git a/main.c b/main.c
index 2fd242f..bb510a8 100644
--- a/main.c
+++ b/main.c
@@ -1293,11 +1293,10 @@ int main(int argc, char **argv)
 	IF_DEBUG(init_coredumps());
 	argv0 = argv[0];
 
-#ifdef ENABLE_NLS	/* never tested */
 	setlocale(LC_ALL, "");
 	bindtextdomain(argv0, CONFIG_EPREFIX "usr/share/locale");
 	textdomain(argv0);
-#endif
+
 #if 1
 	if (fstat(fileno(stdout), &st) != -1)
 		if (!isatty(fileno(stdout)))

diff --git a/qmerge.c b/qmerge.c
index 3aab0ce..572365e 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -1425,7 +1425,7 @@ print_Pkg(int full, struct pkg_t *pkg)
 	printf("%s%s/%s%s%s%s%s%s\n", BOLD, pkg->CATEGORY, BLUE, pkg->PF, NORM,
 		!quiet ? " [" : "",
 		!quiet ? make_human_readable_str(pkg->SIZE, 1, KILOBYTE) : "",
-		!quiet ? "KB]" : "");
+		!quiet ? "KiB]" : "");
 
 	if (full == 0)
 		return;

diff --git a/qsize.c b/qsize.c
index 3cecccb..83ad8b1 100644
--- a/qsize.c
+++ b/qsize.c
@@ -62,8 +62,8 @@ int qsize_main(int argc, char **argv)
 		case 'a': search_all = 1; break;
 		case 's': summary = 1; break;
 		case 'S': summary = summary_only = 1; break;
-		case 'm': disp_units = MEGABYTE; str_disp_units = "MB"; break;
-		case 'k': disp_units = KILOBYTE; str_disp_units = "KB"; break;
+		case 'm': disp_units = MEGABYTE; str_disp_units = "MiB"; break;
+		case 'k': disp_units = KILOBYTE; str_disp_units = "KiB"; break;
 		case 'b': disp_units = 1; str_disp_units = "bytes"; break;
 		case 'i': ignore_regexp = add_set(optarg, optarg, ignore_regexp); break;
 		}
@@ -139,19 +139,20 @@ int qsize_main(int argc, char **argv)
 			num_all_ignored += num_ignored;
 
 			if (!summary_only) {
-				printf("%s%s/%s%s%s: %lu files, %lu non-files, ", BOLD,
+				printf("%s%s/%s%s%s: %'lu files, %'lu non-files, ", BOLD,
 				       catname, BLUE, pkgname, NORM,
 				       (unsigned long)num_files,
 				       (unsigned long)num_nonfiles);
 				if (num_ignored)
-					printf("%lu names-ignored, ", (unsigned long)num_ignored);
+					printf("%'lu names-ignored, ", (unsigned long)num_ignored);
 				if (disp_units)
 					printf("%s %s\n",
 					       make_human_readable_str(num_bytes, 1, disp_units),
 					       str_disp_units);
 				else
-					printf("%lu.%lu KB\n",
+					printf("%'lu%s%lu KiB\n",
 					       (unsigned long)(num_bytes / KILOBYTE),
+					       decimal_point,
 					       (unsigned long)(((num_bytes%KILOBYTE)*1000)/KILOBYTE));
 			}
 
@@ -161,18 +162,19 @@ int qsize_main(int argc, char **argv)
 	}
 
 	if (summary) {
-		printf(" %sTotals%s: %lu files, %lu non-files, ", BOLD, NORM,
+		printf(" %sTotals%s: %'lu files, %'lu non-files, ", BOLD, NORM,
 		       (unsigned long)num_all_files,
 		       (unsigned long)num_all_nonfiles);
 		if (num_all_ignored)
-			printf("%lu names-ignored, ", (unsigned long)num_all_ignored);
+			printf("%'lu names-ignored, ", (unsigned long)num_all_ignored);
 		if (disp_units)
 			printf("%s %s\n",
 			       make_human_readable_str(num_all_bytes, 1, disp_units),
 			       str_disp_units);
 		else
-			printf("%lu.%lu MB\n",
+			printf("%'lu%s%lu MiB\n",
 			       (unsigned long)(num_all_bytes / MEGABYTE),
+			       decimal_point,
 			       (unsigned long)(((num_all_bytes%MEGABYTE)*1000)/MEGABYTE));
 	}
 	free_sets(ignore_regexp);


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2014-03-10  8:45 Mike Frysinger
  0 siblings, 0 replies; 23+ messages in thread
From: Mike Frysinger @ 2014-03-10  8:45 UTC (permalink / raw
  To: gentoo-commits

commit:     bc7d4c9bf7245e9a97f504fd229f2b850358749b
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Mon Mar 10 08:11:14 2014 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Mon Mar 10 08:11:14 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage-utils.git;a=commit;h=bc7d4c9b

vdb: add a q_vdb_pkg_eat helper to unify various call styles

Now that the core eat func is based on dynamic bufs, it's a lot easier
to create a core vdb helper for eating pkg files.

This has the added advantage of making the pkg dir open a delayed call.
We only opendir when we actually want to read files out of it.  For many
funcs which don't do that, it saves a lot of syscall overhead.

---
 libq/vdb.c | 36 ++++++++++++++++++++++++------------
 qcheck.c   |  2 +-
 qdepends.c |  8 ++++----
 qfile.c    |  4 ++--
 qlist.c    | 15 ++-------------
 5 files changed, 33 insertions(+), 32 deletions(-)

diff --git a/libq/vdb.c b/libq/vdb.c
index 2a57bce..dda5e2c 100644
--- a/libq/vdb.c
+++ b/libq/vdb.c
@@ -170,7 +170,8 @@ _q_static void q_vdb_close_cat(q_vdb_cat_ctx *cat_ctx)
 
 typedef struct {
 	const char *name;
-	const char *slot;
+	char *slot;
+	size_t slot_len;
 	int fd;
 	q_vdb_cat_ctx *cat_ctx;
 } q_vdb_pkg_ctx;
@@ -192,17 +193,10 @@ _q_static int q_vdb_filter_pkg(const struct dirent *de)
 
 _q_static q_vdb_pkg_ctx *q_vdb_open_pkg(q_vdb_cat_ctx *cat_ctx, const char *name)
 {
-	q_vdb_pkg_ctx *pkg_ctx;
-	int fd;
-
-	fd = openat(cat_ctx->fd, name, O_RDONLY|O_CLOEXEC|O_PATH);
-	if (fd == -1)
-		return NULL;
-
-	pkg_ctx = xmalloc(sizeof(*pkg_ctx));
+	q_vdb_pkg_ctx *pkg_ctx = xmalloc(sizeof(*pkg_ctx));
 	pkg_ctx->name = name;
 	pkg_ctx->slot = NULL;
-	pkg_ctx->fd = fd;
+	pkg_ctx->fd = -1;
 	pkg_ctx->cat_ctx = cat_ctx;
 	return pkg_ctx;
 }
@@ -229,8 +223,16 @@ _q_static q_vdb_pkg_ctx *q_vdb_next_pkg(q_vdb_cat_ctx *cat_ctx)
 	return pkg_ctx;
 }
 
-#define q_vdb_pkg_openat(pkg_ctx, file, flags, mode...) \
-	openat((pkg_ctx)->fd, file, (flags)|O_CLOEXEC, ## mode)
+_q_static int
+q_vdb_pkg_openat(q_vdb_pkg_ctx *pkg_ctx, const char *file, int flags, mode_t mode)
+{
+	pkg_ctx->fd = openat(pkg_ctx->cat_ctx->fd, pkg_ctx->name, O_RDONLY|O_CLOEXEC|O_PATH);
+	if (pkg_ctx->fd == -1)
+		return -1;
+
+	return openat(pkg_ctx->fd, file, flags|O_CLOEXEC, mode);
+}
+
 _q_static FILE *q_vdb_pkg_fopenat(q_vdb_pkg_ctx *pkg_ctx, const char *file,
 	int flags, mode_t mode, const char *fmode)
 {
@@ -250,10 +252,20 @@ _q_static FILE *q_vdb_pkg_fopenat(q_vdb_pkg_ctx *pkg_ctx, const char *file,
 #define q_vdb_pkg_fopenat_ro(pkg_ctx, file) q_vdb_pkg_fopenat(pkg_ctx, file, O_RDONLY, 0, "r")
 #define q_vdb_pkg_fopenat_rw(pkg_ctx, file) q_vdb_pkg_fopenat(pkg_ctx, file, O_RDWR|O_CREAT|O_TRUNC, 0644, "w")
 
+_q_static bool
+q_vdb_pkg_eat(q_vdb_pkg_ctx *pkg_ctx, const char *file, char **bufptr, size_t *buflen)
+{
+	int fd = q_vdb_pkg_openat(pkg_ctx, file, O_RDONLY, 0);
+	bool ret = eat_file_fd(fd, bufptr, buflen);
+	rmspace(*bufptr);
+	return ret;
+}
+
 _q_static void q_vdb_close_pkg(q_vdb_pkg_ctx *pkg_ctx)
 {
 	if (pkg_ctx->fd != -1)
 		close(pkg_ctx->fd);
+	free(pkg_ctx->slot);
 	free(pkg_ctx);
 }
 

diff --git a/qcheck.c b/qcheck.c
index 4791430..0a98398 100644
--- a/qcheck.c
+++ b/qcheck.c
@@ -69,7 +69,7 @@ static int qcheck_process_contents(q_vdb_pkg_ctx *pkg_ctx, struct qcheck_opt_sta
 
 	fpx = NULL;
 
-	fd = q_vdb_pkg_openat(pkg_ctx, "CONTENTS", O_RDONLY|O_CLOEXEC);
+	fd = q_vdb_pkg_openat(pkg_ctx, "CONTENTS", O_RDONLY|O_CLOEXEC, 0);
 	if (fd == -1)
 		return EXIT_SUCCESS;
 	if (fstat(fd, &cst)) {

diff --git a/qdepends.c b/qdepends.c
index 8a176b6..bc51e02 100644
--- a/qdepends.c
+++ b/qdepends.c
@@ -413,7 +413,7 @@ _q_static int qdepends_main_vdb_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 
 	IF_DEBUG(warn("matched %s/%s", catname, pkgname));
 
-	if (!eat_file_at(pkg_ctx->fd, state->depend_file, &depend, &depend_len))
+	if (!q_vdb_pkg_eat(pkg_ctx, state->depend_file, &depend, &depend_len))
 		return 0;
 
 	IF_DEBUG(warn("growing tree..."));
@@ -434,7 +434,7 @@ _q_static int qdepends_main_vdb_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 		printf("%s%s/%s%s%s: ", BOLD, catname, BLUE, pkgname, NORM);
 	}
 
-	if (!eat_file_at(pkg_ctx->fd, "USE", &use, &use_len)) {
+	if (!q_vdb_pkg_eat(pkg_ctx, "USE", &use, &use_len)) {
 		warn("Could not eat_file(%s), you'll prob have incorrect output", buf);
 	} else {
 		for (ptr = use; *ptr; ++ptr)
@@ -473,7 +473,7 @@ _q_static int qdepends_vdb_deep_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 
 	IF_DEBUG(warn("matched %s/%s for %s", catname, pkgname, state->depend_file));
 
-	if (!eat_file_at(pkg_ctx->fd, state->depend_file, &depend, &depend_len))
+	if (!q_vdb_pkg_eat(pkg_ctx, state->depend_file, &depend, &depend_len))
 		return 0;
 
 	IF_DEBUG(warn("growing tree..."));
@@ -483,7 +483,7 @@ _q_static int qdepends_vdb_deep_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 	IF_DEBUG(puts(depend));
 	IF_DEBUG(dep_dump_tree(dep_tree));
 
-	if (eat_file_at(pkg_ctx->fd, "USE", &use, &use_len))
+	if (q_vdb_pkg_eat(pkg_ctx, "USE", &use, &use_len))
 		use[0] = ' ';
 
 	for (ptr = use; *ptr; ++ptr)

diff --git a/qfile.c b/qfile.c
index 7094034..a32e512 100644
--- a/qfile.c
+++ b/qfile.c
@@ -114,7 +114,7 @@ _q_static int qfile_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 		}
 		if (state->exclude_slot == NULL)
 			goto qlist_done; /* "(CAT/)?(PN|PF)" matches, and no SLOT specified */
-		eat_file_at(pkg_ctx->fd, "SLOT", &state->buf, &state->buflen);
+		q_vdb_pkg_eat(pkg_ctx, "SLOT", &state->buf, &state->buflen);
 		rmspace(state->buf);
 		if (strcmp(state->exclude_slot, state->buf) == 0)
 			goto qlist_done; /* "(CAT/)?(PN|PF):SLOT" matches */
@@ -218,7 +218,7 @@ _q_static int qfile_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 					/* XXX: This assumes the buf is big enough. */
 					char *slot_hack = slot + 1;
 					size_t slot_len = sizeof(slot) - 1;
-					eat_file_at(pkg_ctx->fd, "SLOT", &slot_hack, &slot_len);
+					q_vdb_pkg_eat(pkg_ctx, "SLOT", &slot_hack, &slot_len);
 					rmspace(slot_hack);
 					slot[0] = ':';
 				} else

diff --git a/qlist.c b/qlist.c
index cfb9d98..7755736 100644
--- a/qlist.c
+++ b/qlist.c
@@ -61,17 +61,6 @@ _q_static queue *filter_dups(queue *sets)
 	return dups;
 }
 
-_q_static char *q_vdb_pkg_eat(q_vdb_pkg_ctx *pkg_ctx, const char *item)
-{
-	static char *buf;
-	static size_t buf_len;
-
-	eat_file_at(pkg_ctx->fd, item, &buf, &buf_len);
-	rmspace(buf);
-
-	return buf;
-}
-
 static char *grab_pkg_umap(const char *CAT, const char *PV)
 {
 	static char umap[BUFSIZ];
@@ -159,7 +148,7 @@ qlist_match(q_vdb_pkg_ctx *pkg_ctx, const char *name, depend_atom **name_atom, b
 	if (uslot) {
 		++uslot;
 		if (!pkg_ctx->slot)
-			pkg_ctx->slot = q_vdb_pkg_eat(pkg_ctx, "SLOT");
+			q_vdb_pkg_eat(pkg_ctx, "SLOT", &pkg_ctx->slot, &pkg_ctx->slot_len);
 	}
 
 	/* maybe they're using a version range */
@@ -298,7 +287,7 @@ _q_static int qlist_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 		atom = (verbose ? NULL : atom_explode(pkgname));
 		if ((state->all + state->just_pkgname) < 2) {
 			if (state->show_slots && !pkg_ctx->slot)
-				pkg_ctx->slot = q_vdb_pkg_eat(pkg_ctx, "SLOT");
+				q_vdb_pkg_eat(pkg_ctx, "SLOT", &pkg_ctx->slot, &pkg_ctx->slot_len);
 			/* display it */
 			printf("%s%s/%s%s%s%s%s%s%s%s%s%s\n", BOLD, catname, BLUE,
 				(!state->columns ? (atom ? atom->PN : pkgname) : atom->PN),


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2014-03-21  5:32 Mike Frysinger
  0 siblings, 0 replies; 23+ messages in thread
From: Mike Frysinger @ 2014-03-21  5:32 UTC (permalink / raw
  To: gentoo-commits

commit:     214d027f0d92d1d042451765e875f0a84c3fa37d
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Fri Mar 21 05:28:35 2014 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Fri Mar 21 05:28:35 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage-utils.git;a=commit;h=214d027f

which: punt!

This code is only used by --install, and only when /proc/self/exe does
not work.  We rarely utilize --install, and it's rare for /proc to be
broken in a way we can't rely on.  So having this func just for that
does not make much sense.

Even then, the code was not correct.  It walked $PATH in reverse order
(when it should have been forward order), and it would abort scanning
beofre it checked the first element.  It also doesn't support empty
path elements (which is supposed to be $PWD).

If we want a which() in the future, we can grab the updated version
from Gentoo's pax-utils project.

---
 .depend      |  2 +-
 Makefile.am  |  1 -
 libq/libq.c  |  1 -
 libq/which.c | 25 -------------------------
 q.c          | 13 ++++---------
 5 files changed, 5 insertions(+), 37 deletions(-)

diff --git a/.depend b/.depend
index 259c95c..3b63d1f 100644
--- a/.depend
+++ b/.depend
@@ -1,7 +1,7 @@
 main.o: main.c porting.h main.h libq/libq.c libq/busybox.h libq/i18n.h \
  libq/libq.h libq/colors.c libq/xmalloc.c libq/xstrdup.c libq/xasprintf.c \
  libq/hash_fd.c libq/md5_sha1_sum.c libq/human_readable.c libq/rmspace.c \
- libq/which.c libq/compat.c libq/copy_file.c libq/safe_io.c libq/xchdir.c \
+ libq/compat.c libq/copy_file.c libq/safe_io.c libq/xchdir.c \
  libq/xgetcwd.c libq/xmkdir.c libq/xreadlink.c libq/xregex.c \
  libq/xsystem.c libq/xarray.c libq/atom_explode.c libq/atom_compare.c \
  libq/basename.c libq/scandirat.c libq/prelink.c libq/profile.c \

diff --git a/Makefile.am b/Makefile.am
index ed5c184..14bc649 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -112,7 +112,6 @@ EXTRA_DIST += \
 	libq/vdb.c \
 	libq/vdb_get_next_dir.c \
 	libq/virtuals.c \
-	libq/which.c \
 	libq/xarray.c \
 	libq/xasprintf.c \
 	libq/xchdir.c \

diff --git a/libq/libq.c b/libq/libq.c
index 528db75..5c6eb5c 100644
--- a/libq/libq.c
+++ b/libq/libq.c
@@ -17,7 +17,6 @@
 #include "md5_sha1_sum.c"
 #include "human_readable.c"
 #include "rmspace.c"
-#include "which.c"
 #include "compat.c"
 
 #include "copy_file.c"

diff --git a/libq/which.c b/libq/which.c
deleted file mode 100644
index ce33121..0000000
--- a/libq/which.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/* find the path to a file by name */
-static char *which(const char *fname)
-{
-	static char fullpath[BUFSIZ];
-	char *ret, *path, *p;
-
-	ret = NULL;
-
-	path = getenv("PATH");
-	if (!path)
-		return ret;
-
-	path = xstrdup(path);
-	while ((p = strrchr(path, ':')) != NULL) {
-		snprintf(fullpath, sizeof(fullpath), "%s/%s", p + 1, fname);
-		*p = 0;
-		if (access(fullpath, R_OK) != -1) {
-			ret = fullpath;
-			break;
-		}
-	}
-	free(path);
-
-	return ret;
-}

diff --git a/q.c b/q.c
index 394a035..443ce4b 100644
--- a/q.c
+++ b/q.c
@@ -104,15 +104,10 @@ int q_main(int argc, char **argv)
 
 		rret = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
 		if (rret == -1) {
-			char *ptr = which("q");
-			if (ptr == NULL) {
-				warnfp("haha no symlink love for you");
-				return 1;
-			}
-			strncpy(buf, ptr, sizeof(buf));
-			buf[sizeof(buf) - 1] = '\0';
-		} else
-			buf[rret] = '\0';
+			warnfp("haha no symlink love for you");
+			return 1;
+		}
+		buf[rret] = '\0';
 
 		prog = basename(buf);
 		dir = dirname(buf);


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2015-02-24  1:26 Mike Frysinger
  0 siblings, 0 replies; 23+ messages in thread
From: Mike Frysinger @ 2015-02-24  1:26 UTC (permalink / raw
  To: gentoo-commits

commit:     657234dd353ffc2ee1f464634aa8950260317404
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 22 09:02:54 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sun Feb 22 09:02:54 2015 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage-utils.git;a=commit;h=657234dd

qmerge: support running pkg funcs in a dir via fd

---
 libq/xsystem.c | 5 ++++-
 qmerge.c       | 5 +++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/libq/xsystem.c b/libq/xsystem.c
index 199a1d2..d8a551a 100644
--- a/libq/xsystem.c
+++ b/libq/xsystem.c
@@ -14,13 +14,16 @@ static void xsystem(const char *command)
 		errp("system(%s) failed", command);
 }
 
-static void xsystembash(const char *command)
+static void xsystembash(const char *command, int cwd)
 {
 	pid_t p = vfork();
 	int status;
 
 	switch (p) {
 	case 0: /* child */
+		if (cwd != AT_FDCWD)
+			if (fchdir(cwd))
+				errp("fchdir failed");
 		execl("/bin/bash", "bash", "--norc", "--noprofile", "-c", command, NULL);
 		/* Hrm, still here ?  Maybe no bash ... */
 		_exit(execl("/bin/sh", "sh", "-c", command, NULL));

diff --git a/qmerge.c b/qmerge.c
index c58e4f2..980a5b6 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -417,7 +417,7 @@ qprint_tree_node(int level, const depend_atom *atom, const struct pkg_t *pkg)
 }
 
 _q_static void
-pkg_run_func(const char *vdb_path, const char *phases, const char *func, const char *D, const char *T)
+pkg_run_func_at(int dirfd, const char *vdb_path, const char *phases, const char *func, const char *D, const char *T)
 {
 	const char *phase;
 	char *script;
@@ -484,9 +484,10 @@ pkg_run_func(const char *vdb_path, const char *phases, const char *func, const c
 		/*5*/ D,
 		/*6*/ T,
 		/*7*/ debug ? "set -x;" : "");
-	xsystembash(script);
+	xsystembash(script, dirfd);
 	free(script);
 }
+#define pkg_run_func(...) pkg_run_func_at(AT_FDCWD, __VA_ARGS__)
 
 /* Copy one tree (the single package) to another tree (ROOT) */
 _q_static int


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2015-11-28  2:44 Mike Frysinger
  0 siblings, 0 replies; 23+ messages in thread
From: Mike Frysinger @ 2015-11-28  2:44 UTC (permalink / raw
  To: gentoo-commits

commit:     92de436359da8f14b7dbef5f62af959095b79d06
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Fri Nov 27 18:14:14 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Fri Nov 27 18:14:14 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=92de4363

use the return value of getline

This allows us to avoid calling strlen to get a value getline already
calculated.  We can also pass this value on to rmspace to let it trim
space for us.

 libq/colors.c  | 16 ++++++----------
 libq/profile.c |  7 ++++---
 libq/rmspace.c |  8 ++++++--
 main.c         |  1 +
 qcache.c       |  9 ++++-----
 qfile.c        |  8 ++++----
 qlop.c         | 19 ++++++++-----------
 qmerge.c       | 15 +++++++--------
 qsearch.c      | 11 +++++------
 quse.c         | 25 ++++++++++---------------
 10 files changed, 55 insertions(+), 64 deletions(-)

diff --git a/libq/colors.c b/libq/colors.c
index bd2c1e0..6ddcdda 100644
--- a/libq/colors.c
+++ b/libq/colors.c
@@ -50,7 +50,7 @@ void color_remap(void)
 {
 	FILE *fp;
 	unsigned int i;
-	size_t buflen;
+	size_t buflen, linelen;
 	char *buf;
 	char *p;
 	unsigned int lineno = 0;
@@ -59,22 +59,18 @@ void color_remap(void)
 		return;
 
 	buf = NULL;
-	while (getline(&buf, &buflen, fp) != -1) {
+	while ((linelen = getline(&buf, &buflen, fp)) != -1) {
 		lineno++;
 		/* eat comments */
 		if ((p = strchr(buf, '#')) != NULL)
 			*p = '\0';
 
-		if (strchr(buf, '=') == NULL)
-			continue;
-
-		/* eat the end of the buffer first */
-		if ((p = strchr(buf, '\r')) != NULL)
-			*p = 0;
-		if ((p = strchr(buf, '\n')) != NULL)
-			*p = 0;
+		rmspace_len(buf, linelen);
 
 		p = strchr(buf, '=');
+		if (p == NULL)
+			continue;
+
 		*p++ = 0; /* split the pair */
 		for (i = 0; i < ARRAY_SIZE(color_pairs); ++i)
 			if (strcmp(buf, color_pairs[i].name) == 0) {

diff --git a/libq/profile.c b/libq/profile.c
index 75f3cb0..66e5caf 100644
--- a/libq/profile.c
+++ b/libq/profile.c
@@ -6,7 +6,7 @@ q_profile_walk_at(int dir_fd, const char *dir, const char *file,
 {
 	FILE *fp;
 	int subdir_fd, fd;
-	size_t buflen;
+	size_t buflen, linelen;
 	char *buf;
 
 	/* Pop open this profile dir */
@@ -46,13 +46,14 @@ q_profile_walk_at(int dir_fd, const char *dir, const char *file,
 	}
 
 	buf = NULL;
-	while (getline(&buf, &buflen, fp) != -1) {
+	while ((linelen = getline(&buf, &buflen, fp)) != -1) {
 		char *s;
 
+		rmspace_len(buf, linelen);
+
 		s = strchr(buf, '#');
 		if (s)
 			*s = '\0';
-		rmspace(buf);
 
 		data = q_profile_walk_at(subdir_fd, buf, file, callback, data);
 	}

diff --git a/libq/rmspace.c b/libq/rmspace.c
index d374d7f..b8ac5a3 100644
--- a/libq/rmspace.c
+++ b/libq/rmspace.c
@@ -1,9 +1,8 @@
 
 /* removed leading/trailing extraneous white space */
-static char *rmspace(char *s)
+static char *rmspace_len(char *s, size_t len)
 {
 	char *p;
-	size_t len = strlen(s);
 	/* find the start of trailing space and set it to \0 */
 	for (p = s + len - 1; (p >= s && isspace(*p)); --p)
 		continue;
@@ -17,3 +16,8 @@ static char *rmspace(char *s)
 		memmove(s, p, len - (p - s) + 1);
 	return s;
 }
+
+static char *rmspace(char *s)
+{
+	return rmspace_len(s, strlen(s));
+}

diff --git a/main.c b/main.c
index 10af2db..42a3f26 100644
--- a/main.c
+++ b/main.c
@@ -15,6 +15,7 @@ static bool eat_file_fd(int, char **, size_t *);
 static bool eat_file_at(int, const char *, char **, size_t *);
 int rematch(const char *, const char *, int);
 static char *rmspace(char *);
+static char *rmspace_len(char *, size_t);
 
 void initialize_portage_env(void);
 void initialize_ebuild_flat(void);

diff --git a/qcache.c b/qcache.c
index 0968d33..5f65fe0 100644
--- a/qcache.c
+++ b/qcache.c
@@ -319,10 +319,10 @@ _q_static
 portage_cache *qcache_read_cache_file(const char *filename)
 {
 	struct stat s;
-	char *ptr, *buf;
+	char *buf;
 	FILE *f;
 	portage_cache *ret = NULL;
-	size_t len, buflen;
+	size_t len, buflen, linelen;
 
 	if ((f = fopen(filename, "r")) == NULL)
 		goto err;
@@ -336,9 +336,8 @@ portage_cache *qcache_read_cache_file(const char *filename)
 	len = sizeof(*ret) + s.st_size + 1;
 	ret = xzalloc(len);
 
-	while (getline(&buf, &buflen, f) != -1) {
-		if ((ptr = strrchr(buf, '\n')) != NULL)
-			*ptr = 0;
+	while ((linelen = getline(&buf, &buflen, f)) != -1) {
+		rmspace_len(buf, linelen);
 
 		if (strncmp(buf, "DEPEND=", 7) == 0)
 			ret->DEPEND = xstrdup(buf + 7);

diff --git a/qfile.c b/qfile.c
index a32e512..6d36e96 100644
--- a/qfile.c
+++ b/qfile.c
@@ -513,10 +513,10 @@ int qfile_main(int argc, char **argv)
 			for (i = 0; i < qargc; ++i)
 				free(qargv[i]);
 			qargc = 0;
-			while (getline(&state.buf, &state.buflen, args_file) != -1) {
-				if ((p = strchr(state.buf, '\n')) != NULL)
-					*p = '\0';
-				if (state.buf == p)
+			size_t linelen;
+			while ((linelen = getline(&state.buf, &state.buflen, args_file)) != -1) {
+				rmspace_len(state.buf, linelen);
+				if (state.buf[0] == '\0')
 					continue;
 				qargv[qargc] = xstrdup(state.buf);
 				if (++qargc >= max_args)

diff --git a/qlop.c b/qlop.c
index 390865a..f2f97c6 100644
--- a/qlop.c
+++ b/qlop.c
@@ -240,7 +240,7 @@ _q_static void
 show_emerge_history(char listflag, int argc, char **argv, const char *logfile)
 {
 	FILE *fp;
-	size_t buflen;
+	size_t buflen, linelen;
 	char *buf, merged;
 	char *p, *q;
 	int i;
@@ -252,8 +252,8 @@ show_emerge_history(char listflag, int argc, char **argv, const char *logfile)
 	}
 
 	buf = NULL;
-	while (getline(&buf, &buflen, fp) != -1) {
-		if (strlen(buf) < 30)
+	while ((linelen = getline(&buf, &buflen, fp)) != -1) {
+		if (linelen < 30)
 			continue;
 
 		for (i = 0; i < argc; ++i)
@@ -262,8 +262,7 @@ show_emerge_history(char listflag, int argc, char **argv, const char *logfile)
 		if (argc && i == argc)
 			continue;
 
-		if ((p = strchr(buf, '\n')) != NULL)
-			*p = 0;
+		rmspace_len(buf, linelen);
 		if ((p = strchr(buf, ':')) == NULL)
 			continue;
 		*p = 0;
@@ -327,7 +326,7 @@ _q_static void
 show_sync_history(const char *logfile)
 {
 	FILE *fp;
-	size_t buflen, len;
+	size_t buflen, linelen;
 	char *buf, *p;
 	time_t t;
 
@@ -338,10 +337,9 @@ show_sync_history(const char *logfile)
 
 	buf = NULL;
 	/* Just find the finish lines. */
-	while (getline(&buf, &buflen, fp) != -1) {
-		len = strlen(buf);
+	while ((linelen = getline(&buf, &buflen, fp)) != -1) {
 		/* This cuts out like ~10% of the log. */
-		if (len < 35)
+		if (linelen < 35)
 			continue;
 
 		/* Make sure there's a timestamp in here. */
@@ -353,8 +351,7 @@ show_sync_history(const char *logfile)
 			continue;
 		p += 19;
 
-		if (buf[len - 1] == '\n')
-			buf[len - 1] = '\0';
+		rmspace_len(buf, linelen);
 
 		t = (time_t)atol(buf);
 

diff --git a/qmerge.c b/qmerge.c
index ddc0a10..297f939 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -1633,7 +1633,7 @@ _q_static int
 parse_packages(queue *todo)
 {
 	FILE *fp;
-	size_t buflen;
+	size_t buflen, linelen;
 	char *buf, *p;
 	struct pkg_t Pkg;
 	depend_atom *pkg_atom;
@@ -1645,12 +1645,11 @@ parse_packages(queue *todo)
 	repo[0] = '\0';
 
 	/* First consume the header with the common data. */
-	while (getline(&buf, &buflen, fp) != -1) {
-		if (*buf == '\n')
+	while ((linelen = getline(&buf, &buflen, fp)) != -1) {
+		rmspace_len(buf, linelen);
+		if (buf[0] == '\0')
 			break;
 
-		if ((p = strchr(buf, '\n')) != NULL)
-			*p = 0;
 		if ((p = strchr(buf, ':')) == NULL)
 			continue;
 		if (p[1] != ' ')
@@ -1766,7 +1765,7 @@ _q_static queue *
 qmerge_add_set_file(const char *dir, const char *file, queue *set)
 {
 	FILE *fp;
-	size_t buflen;
+	size_t buflen, linelen;
 	char *buf, *fname;
 
 	/* Find the file to read */
@@ -1781,8 +1780,8 @@ qmerge_add_set_file(const char *dir, const char *file, queue *set)
 
 	/* Load each entry */
 	buf = NULL;
-	while (getline(&buf, &buflen, fp) != -1) {
-		rmspace(buf);
+	while ((linelen = getline(&buf, &buflen, fp)) != -1) {
+		rmspace_len(buf, linelen);
 		set = add_set(buf, set);
 	}
 	free(buf);

diff --git a/qsearch.c b/qsearch.c
index 427580d..02d43ca 100644
--- a/qsearch.c
+++ b/qsearch.c
@@ -41,7 +41,7 @@ int qsearch_main(int argc, char **argv)
 	char show_homepage = 0, show_name_only = 0;
 	char search_desc = 0, search_all = 0, search_name = 1, search_cache = CACHE_EBUILD;
 	const char *search_vars[] = { "DESCRIPTION=", "HOMEPAGE=" };
-	size_t search_len, ebuild_len;
+	size_t search_len, ebuild_len, linelen;
 	int i, idx=0;
 
 	DBG("argc=%d argv[0]=%s argv[1]=%s",
@@ -80,9 +80,8 @@ int qsearch_main(int argc, char **argv)
 	q = NULL; /* Silence a gcc warning. */
 	search_len = strlen(search_vars[idx]);
 
-	while (getline(&ebuild, &ebuild_len, fp) != -1) {
-		if ((p = strchr(ebuild, '\n')) != NULL)
-			*p = 0;
+	while ((linelen = getline(&ebuild, &ebuild_len, fp)) != -1) {
+		rmspace_len(ebuild, linelen);
 		if (!ebuild[0])
 			continue;
 
@@ -141,8 +140,8 @@ int qsearch_main(int argc, char **argv)
 
 				char *buf = NULL;
 				size_t buflen;
-				while (getline(&buf, &buflen, ebuildfp) != -1) {
-					if (strlen(buf) <= search_len)
+				while ((linelen = getline(&buf, &buflen, ebuildfp)) != -1) {
+					if (linelen <= search_len)
 						continue;
 					if (strncmp(buf, search_vars[idx], search_len) != 0)
 						continue;

diff --git a/quse.c b/quse.c
index ab257bf..8ba0be1 100644
--- a/quse.c
+++ b/quse.c
@@ -82,7 +82,7 @@ static void
 quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, char **argv)
 {
 #define NUM_SEARCH_FILES ARRAY_SIZE(search_files)
-	size_t buflen;
+	size_t buflen, linelen;
 	char *buf, *p;
 	unsigned int i, f;
 	size_t s;
@@ -110,13 +110,11 @@ quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, cha
 			if (fp[f] == NULL)
 				continue;
 
-			while (getline(&buf, &buflen, fp[f]) != -1) {
-				if (buf[0] == '#' || buf[0] == '\n')
+			while ((linelen = getline(&buf, &buflen, fp[f])) != -1) {
+				rmspace_len(buf, linelen);
+				if (buf[0] == '#' || buf[0] == '\0')
 					continue;
 
-				if ((p = strrchr(buf, '\n')) != NULL)
-					*p = '\0';
-
 				switch (f) {
 					case 0: /* Global use.desc */
 						if (!strncmp(buf, argv[i], s))
@@ -193,13 +191,11 @@ quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, cha
 		/* Chop the trailing .desc for better display */
 		*p = '\0';
 
-		while (getline(&buf, &buflen, fp[0]) != -1) {
-			if (buf[0] == '#' || buf[0] == '\n')
+		while ((linelen = getline(&buf, &buflen, fp[0])) != -1) {
+			rmspace_len(buf, linelen);
+			if (buf[0] == '#' || buf[0] == '\0')
 				continue;
 
-			if ((p = strrchr(buf, '\n')) != NULL)
-				*p = '\0';
-
 			if ((p = strchr(buf, '-')) == NULL) {
  invalid_line:
 				warn("Invalid line in '%s': %s", de->d_name, buf);
@@ -235,7 +231,7 @@ int quse_main(int argc, char **argv)
 	char buf1[_Q_PATH_MAX];
 	char buf2[_Q_PATH_MAX];
 
-	size_t ebuildlen;
+	size_t ebuildlen, linelen;
 	char *ebuild;
 
 	const char *search_var = NULL;
@@ -284,12 +280,11 @@ int quse_main(int argc, char **argv)
 	int portdir_fd = open(portdir, O_RDONLY|O_CLOEXEC|O_PATH);
 
 	ebuild = NULL;
-	while (getline(&ebuild, &ebuildlen, fp) != -1) {
+	while ((linelen = getline(&ebuild, &ebuildlen, fp)) != -1) {
 		FILE *newfp;
 		int fd;
 
-		if ((p = strchr(ebuild, '\n')) != NULL)
-			*p = 0;
+		rmspace_len(ebuild, linelen);
 
 		fd = openat(portdir_fd, ebuild, O_RDONLY|O_CLOEXEC);
 		if (fd < 0)


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2015-11-28  2:44 Mike Frysinger
  0 siblings, 0 replies; 23+ messages in thread
From: Mike Frysinger @ 2015-11-28  2:44 UTC (permalink / raw
  To: gentoo-commits

commit:     89d451252b18c0ae2f768f6248964638f8aadd9f
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Fri Nov 27 22:45:50 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Fri Nov 27 22:45:50 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=89d45125

qcache: add multiple overlay support

We have to rework two things:
 - turn the arch array into a set; the implementation is not optimal
 - pass in the current overlay to the callback func so it can keep
   track of when we switch between them

With that in place, walking all the overlays is pretty quick.

URL: https://bugs.gentoo.org/553260

 libq/virtuals.c |  16 +++++++
 qcache.c        | 131 +++++++++++++++++++++++++++++++++-----------------------
 2 files changed, 94 insertions(+), 53 deletions(-)

diff --git a/libq/virtuals.c b/libq/virtuals.c
index 536c622..1818281 100644
--- a/libq/virtuals.c
+++ b/libq/virtuals.c
@@ -46,6 +46,22 @@ add_set(const char *name, queue *q)
 	return append_set(q, ll);
 }
 
+/* Performance here is terrible.  Should use a hash at some point. */
+_q_static queue *
+add_set_unique(const char *name, queue *q, bool *ok)
+{
+	queue *ll = q;
+	while (ll) {
+		if (!strcmp(ll->name, name)) {
+			*ok = false;
+			return q;
+		}
+		ll = ll->next;
+	}
+	*ok = true;
+	return add_set(name, q);
+}
+
 /* remove a set from a cache. matches ->name and frees name,item */
 _q_static queue *
 del_set(char *s, queue *q, int *ok)

diff --git a/qcache.c b/qcache.c
index 5cac394..d4b7884 100644
--- a/qcache.c
+++ b/qcache.c
@@ -51,9 +51,10 @@ static const char * const qcache_opts_help[] = {
 /********************************************************************/
 
 typedef struct {
-	char *category;
-	char *package;
-	char *ebuild;
+	const char *overlay;
+	const char *category;
+	const char *package;
+	const char *ebuild;
 	portage_cache *cache_data;
 	unsigned char cur;
 	unsigned char num;
@@ -63,7 +64,7 @@ typedef struct {
 /* Global Variables                                                 */
 /********************************************************************/
 
-static char **archlist; /* Read from PORTDIR/profiles/arch.list in qcache_init() */
+static queue *arches;
 static int archlist_count;
 static size_t arch_longest_len;
 const char status[3] = {'-', '~', '+'};
@@ -113,6 +114,7 @@ int decode_status(char c)
 _q_static
 int decode_arch(const char *arch)
 {
+	queue *q = arches;
 	int a;
 	const char *p;
 
@@ -120,9 +122,13 @@ int decode_arch(const char *arch)
 	if (*p == '~' || *p == '-')
 		p++;
 
-	for (a = 0; a < archlist_count; ++a)
-		if (strcmp(archlist[a], p) == 0)
+	a = 0;
+	while (q) {
+		if (strcmp(q->name, p) == 0)
 			return a;
+		++a;
+		q = q->next;
+	}
 
 	return -1;
 }
@@ -139,6 +145,7 @@ int decode_arch(const char *arch)
 _q_static
 void print_keywords(const char *category, const char *ebuild, int *keywords)
 {
+	queue *arch = arches;
 	int a;
 	char *package;
 
@@ -149,14 +156,13 @@ void print_keywords(const char *category, const char *ebuild, int *keywords)
 	for (a = 0; a < archlist_count; ++a) {
 		switch (keywords[a]) {
 			case stable:
-				printf("%s%c%s%s ", GREEN, status[keywords[a]], archlist[a], NORM);
+				printf("%s%c%s%s ", GREEN, status[keywords[a]], arch->name, NORM);
 				break;
 			case testing:
-				printf("%s%c%s%s ", YELLOW, status[keywords[a]], archlist[a], NORM);
-				break;
-			default:
+				printf("%s%c%s%s ", YELLOW, status[keywords[a]], arch->name, NORM);
 				break;
 		}
+		arch = arch->next;
 	}
 
 	printf("\n");
@@ -386,6 +392,8 @@ int qcache_ebuild_select(const struct dirent *entry)
 /* Traversal function                                               */
 /********************************************************************/
 
+_q_static void qcache_load_arches(const char *overlay);
+
 /*
  * int qcache_traverse(void (*func)(qcache_data*));
  *
@@ -399,14 +407,16 @@ int qcache_ebuild_select(const struct dirent *entry)
  *  exit or return -1 on failure.
  */
 _q_static
-int qcache_traverse(void (*func)(qcache_data*))
+int qcache_traverse_overlay(void (*func)(qcache_data*), const char *overlay)
 {
-	qcache_data data;
+	qcache_data data = {
+		.overlay = overlay,
+	};
 	char *catpath, *pkgpath, *ebuildpath, *cachepath;
 	int i, j, k, len, num_cat, num_pkg, num_ebuild;
 	struct dirent **categories, **packages, **ebuilds;
 
-	xasprintf(&catpath, "%s/dep/%s", portedb, portdir);
+	xasprintf(&catpath, "%s/dep/%s", portedb, overlay);
 
 	if (-1 == (num_cat = scandir(catpath, &categories, qcache_file_select, alphasort))) {
 		errp("%s", catpath);
@@ -418,7 +428,7 @@ int qcache_traverse(void (*func)(qcache_data*))
 
 	/* traverse categories */
 	for (i = 0; i < num_cat; i++) {
-		xasprintf(&pkgpath, "%s/%s", portdir, categories[i]->d_name);
+		xasprintf(&pkgpath, "%s/%s", overlay, categories[i]->d_name);
 
 		if (-1 == (num_pkg = scandir(pkgpath, &packages, qcache_file_select, alphasort))) {
 			if (errno != ENOENT)
@@ -439,7 +449,7 @@ int qcache_traverse(void (*func)(qcache_data*))
 
 		/* traverse packages */
 		for (j = 0; j < num_pkg; j++) {
-			xasprintf(&ebuildpath, "%s/%s/%s", portdir, categories[i]->d_name, packages[j]->d_name);
+			xasprintf(&ebuildpath, "%s/%s/%s", overlay, categories[i]->d_name, packages[j]->d_name);
 
 			if (-1 == (num_ebuild = scandir(ebuildpath, &ebuilds, qcache_ebuild_select, qcache_vercmp))) {
 				/* Do not complain about spurious files */
@@ -504,9 +514,28 @@ int qcache_traverse(void (*func)(qcache_data*))
 	free(categories);
 	free(catpath);
 
+	return 0;
+}
+
+_q_static
+int qcache_traverse(void (*func)(qcache_data*))
+{
+	int ret;
+	size_t n;
+	const char *overlay;
+
+	/* Preload all the arches. Not entirely correctly (as arches are bound
+	 * to overlays if set), but oh well. */
+	array_for_each(overlays, n, overlay)
+		qcache_load_arches(overlay);
+
+	ret = 0;
+	array_for_each(overlays, n, overlay)
+		ret |= qcache_traverse_overlay(func, overlay);
+
 	func(NULL);
 
-	return 0;
+	return ret;
 }
 
 /********************************************************************/
@@ -653,6 +682,8 @@ _q_static
 void qcache_stats(qcache_data *data)
 {
 	static time_t runtime;
+	static queue *allcats;
+	static const char *last_overlay;
 	static int numpkg  = 0;
 	static int numebld = 0;
 	static int numcat;
@@ -686,12 +717,14 @@ void qcache_stats(qcache_data *data)
 			(int)arch_longest_len, "", RED, "only", NORM);
 		printf("+%.*s+\n", (int)(arch_longest_len + 46), border);
 
+		queue *arch = arches;
 		for (a = 0; a < archlist_count; ++a) {
-			printf("| %s%*s%s |", GREEN, (int)arch_longest_len, archlist[a], NORM);
+			printf("| %s%*s%s |", GREEN, (int)arch_longest_len, arch->name, NORM);
 			printf("%s%8d%s |", BLUE, packages_stable[a], NORM);
 			printf("%s%8d%s |", BLUE, packages_testing[a], NORM);
 			printf("%s%8d%s |", BLUE, packages_testing[a]+packages_stable[a], NORM);
 			printf("%s%11.2f%s%% |\n", BLUE, (100.0*(packages_testing[a]+packages_stable[a]))/numpkg, NORM);
+			arch = arch->next;
 		}
 
 		printf("+%.*s+\n\n", (int)(arch_longest_len + 46), border);
@@ -704,23 +737,33 @@ void qcache_stats(qcache_data *data)
 		free(packages_testing);
 		free(keywords);
 		free(current_package_keywords);
+		free_sets(allcats);
 		return;
 	}
 
-	if (!numpkg) {
-		struct dirent **categories;
+	if (last_overlay != data->overlay) {
+		DIR *dir;
+		struct dirent *de;
 		char *catpath;
 
-		xasprintf(&catpath, "%s/dep/%s", portedb, portdir);
+		runtime = time(NULL);
 
-		if (-1 == (numcat = scandir(catpath, &categories, qcache_file_select, alphasort))) {
-			errp("%s", catpath);
-			free(catpath);
-		}
-		scandir_free(categories, numcat);
+		xasprintf(&catpath, "%s/dep/%s", portedb, data->overlay);
+		dir = opendir(catpath);
+		while ((de = readdir(dir)))
+			if (de->d_type == DT_DIR && de->d_name[0] != '.') {
+				bool ok;
+				allcats = add_set_unique(de->d_name, allcats, &ok);
+				if (ok)
+					++numcat;
+			}
+		closedir(dir);
+		free(catpath);
 
-		runtime = time(NULL);
+		last_overlay = data->overlay;
+	}
 
+	if (!numpkg) {
 		packages_stable          = xcalloc(archlist_count, sizeof(*packages_stable));
 		packages_testing         = xcalloc(archlist_count, sizeof(*packages_testing));
 		keywords                 = xcalloc(archlist_count, sizeof(*keywords));
@@ -812,26 +855,15 @@ void qcache_testing_only(qcache_data *data)
 /* Misc functions                                                   */
 /********************************************************************/
 
-/*
- * int qcache_init();
- *
- * Initialize variables (archlist, num_arches)
- *
- * OUT:
- *  0 is return on success.
- * ERR:
- *  -1 is returned on error.
- */
 _q_static
-bool qcache_init(void)
+void qcache_load_arches(const char *overlay)
 {
-	bool ret = false;
 	FILE *fp;
 	char *filename, *s;
 	size_t buflen, linelen;
 	char *buf;
 
-	xasprintf(&filename, "%s/profiles/arch.list", portdir);
+	xasprintf(&filename, "%s/profiles/arch.list", overlay);
 	fp = fopen(filename, "re");
 	if (!fp)
 		goto done;
@@ -847,18 +879,18 @@ bool qcache_init(void)
 		if (buf[0] == '\0')
 			continue;
 
-		++archlist_count;
-		archlist = xrealloc_array(archlist, sizeof(*archlist), archlist_count);
-		archlist[archlist_count - 1] = xstrdup(buf);
-		arch_longest_len = MAX(arch_longest_len, strlen(buf));
+		bool ok;
+		arches = add_set_unique(buf, arches, &ok);
+		if (ok) {
+			++archlist_count;
+			arch_longest_len = MAX(arch_longest_len, strlen(buf));
+		}
 	}
 	free(buf);
 
-	ret = true;
 	fclose(fp);
  done:
 	free(filename);
-	return ret;
 }
 
 /*
@@ -869,11 +901,7 @@ bool qcache_init(void)
 _q_static
 void qcache_free(void)
 {
-	size_t a;
-
-	for (a = 0; a < archlist_count; ++a)
-		free(archlist[a]);
-	free(archlist);
+	free_sets(arches);
 }
 
 /********************************************************************/
@@ -906,9 +934,6 @@ int qcache_main(int argc, char **argv)
 		}
 	}
 
-	if (!qcache_init())
-		err("Could not initialize arch list");
-
 	if (optind < argc)
 		qcache_test_arch = decode_arch(argv[optind]);
 


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2016-02-14  1:26 Mike Frysinger
  0 siblings, 0 replies; 23+ messages in thread
From: Mike Frysinger @ 2016-02-14  1:26 UTC (permalink / raw
  To: gentoo-commits

commit:     962d51191d7ac490d0a44fd3c370d27841ff43a5
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sat Feb 13 23:13:55 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sat Feb 13 23:13:55 2016 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=962d5119

autogen: pull in inttypes as we use it

This allows us to clean up some of the __INTERIX mess in the process.

 autogen.sh          | 1 +
 libq/hash_fd.c      | 2 --
 libq/md5_sha1_sum.c | 2 --
 porting.h           | 2 --
 4 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/autogen.sh b/autogen.sh
index dbb2aac..4313a84 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -20,6 +20,7 @@ mods="
 	futimens
 	getline
 	getopt-posix
+	inttypes
 	mkdirat
 	openat
 	progname

diff --git a/libq/hash_fd.c b/libq/hash_fd.c
index 3d352da..c021267 100644
--- a/libq/hash_fd.c
+++ b/libq/hash_fd.c
@@ -23,9 +23,7 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <stdio.h>
-#ifndef __INTERIX
 #include <inttypes.h>
-#endif
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>

diff --git a/libq/md5_sha1_sum.c b/libq/md5_sha1_sum.c
index ed6adf0..6232433 100644
--- a/libq/md5_sha1_sum.c
+++ b/libq/md5_sha1_sum.c
@@ -20,9 +20,7 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <stdio.h>
-#ifndef __INTERIX
 #include <inttypes.h>
-#endif
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>

diff --git a/porting.h b/porting.h
index 8045813..28b6317 100644
--- a/porting.h
+++ b/porting.h
@@ -31,9 +31,7 @@
 #include <dirent.h>
 #include <errno.h>
 #include <getopt.h>
-#ifndef __INTERIX
 #include <inttypes.h>
-#endif
 #include <libgen.h>
 #include <limits.h>
 #include <regex.h>


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2016-02-14  1:26 Mike Frysinger
  0 siblings, 0 replies; 23+ messages in thread
From: Mike Frysinger @ 2016-02-14  1:26 UTC (permalink / raw
  To: gentoo-commits

commit:     a713624891de6d3e7b2c9d61f7ff47bd65db89ee
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sat Feb 13 23:30:47 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sat Feb 13 23:30:47 2016 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=a7136248

qlop: parse args as atoms instead of substrings

Update the arg parsing logic to treat them as atoms rather than as
ad-hoc substring parsing.  This makes the listing logic much more
natural and brings it inline with other applets.

URL: https://bugs.gentoo.org/112818
Reported-by: Jeroen Roovers <jer <AT> gentoo.org>

 libq/xarray.c | 31 +++++++++++++++++++--------
 qlop.c        | 68 ++++++++++++++++++++++++++++++++++++-----------------------
 2 files changed, 64 insertions(+), 35 deletions(-)

diff --git a/libq/xarray.c b/libq/xarray.c
index 339d759..36a5df5 100644
--- a/libq/xarray.c
+++ b/libq/xarray.c
@@ -24,24 +24,37 @@ typedef struct {
 #define array_cnt(arr) (arr)->num
 #define DECLARE_ARRAY(arr) array_t _##arr = array_init_decl, *arr = &_##arr
 
-static void *xarraypush(array_t *arr, const void *ele, size_t ele_len)
+/* Push a pointer to memory we already hold and don't want to release.  Do not
+ * mix xarraypush_ptr usage with the other push funcs which duplicate memory.
+ * The free stage won't know which pointers to release directly.
+ */
+static void *xarraypush_ptr(array_t *arr, void *ele)
 {
-	void *nele;
 	size_t n = arr->num++;
 	arr->eles = xrealloc_array(arr->eles, arr->num, sizeof(ele));
-	arr->eles[n] = nele = xmemdup(ele, ele_len);
-	return nele;
+	arr->eles[n] = ele;
+	return ele;
+}
+static void *xarraypush(array_t *arr, const void *ele, size_t ele_len)
+{
+	return xarraypush_ptr(arr, xmemdup(ele, ele_len));
 }
 #define xarraypush_str(arr, ele) xarraypush(arr, ele, strlen(ele) + 1 /*NUL*/)
+#define xarraypush_struct(arr, ele) xarraypush(arr, ele, sizeof(*(ele)))
 
-static void xarrayfree(array_t *arr)
+/* Useful for people who call xarraypush_ptr as it does not free any of the
+ * pointers in the eles list.
+ */
+static void xarrayfree_int(array_t *arr)
 {
 	array_t blank = array_init_decl;
+	free(arr->eles);
+	*arr = blank;
+}
+static void xarrayfree(array_t *arr)
+{
 	size_t n;
-
 	for (n = 0; n < arr->num; ++n)
 		free(arr->eles[n]);
-	free(arr->eles);
-
-	*arr = blank;
+	xarrayfree_int(arr);
 }

diff --git a/qlop.c b/qlop.c
index bb32474..8a89fba 100644
--- a/qlop.c
+++ b/qlop.c
@@ -235,14 +235,15 @@ show_merge_times(char *package, const char *logfile, int average, char human_rea
 }
 
 _q_static void
-show_emerge_history(char listflag, int argc, char **argv, const char *logfile)
+show_emerge_history(int listflag, array_t *atoms, const char *logfile)
 {
 	FILE *fp;
 	size_t buflen, linelen;
 	char *buf, merged;
 	char *p, *q;
-	int i;
+	size_t i;
 	time_t t;
+	depend_atom *atom, *logatom;
 
 	if ((fp = fopen(logfile, "r")) == NULL) {
 		warnp("Could not open logfile '%s'", logfile);
@@ -254,12 +255,6 @@ show_emerge_history(char listflag, int argc, char **argv, const char *logfile)
 		if (linelen < 30)
 			continue;
 
-		for (i = 0; i < argc; ++i)
-			if (strstr(buf, argv[i]) != NULL)
-				break;
-		if (argc && i == argc)
-			continue;
-
 		rmspace_len(buf, linelen);
 		if ((p = strchr(buf, ':')) == NULL)
 			continue;
@@ -286,18 +281,23 @@ show_emerge_history(char listflag, int argc, char **argv, const char *logfile)
 			q = p + 2;
 		} else
 			continue;
-		if (!quiet)
-			printf("%s %s %s%s%s\n", chop_ctime(t), (merged ? ">>>" : "<<<"), (merged ? GREEN : RED), q, NORM);
-		else {
-			depend_atom *atom;
-			atom = atom_explode(q);
-			if (quiet == 1)
-				printf("%s ", chop_ctime(t));
-			if (quiet <= 2)
-				printf("%s ", (merged ? ">>>" : "<<<"));
-			printf("%s%s/%s%s\n", (merged ? GREEN : RED), atom->CATEGORY, atom->PN, NORM);
-			atom_implode(atom);
+
+		logatom = atom_explode(q);
+		array_for_each(atoms, i, atom) {
+			if (atom_compare(atom, logatom) != EQUAL)
+				continue;
+
+			if (!quiet)
+				printf("%s %s %s%s%s\n", chop_ctime(t), (merged ? ">>>" : "<<<"), (merged ? GREEN : RED), q, NORM);
+			else {
+				if (quiet == 1)
+					printf("%s ", chop_ctime(t));
+				if (quiet <= 2)
+					printf("%s ", (merged ? ">>>" : "<<<"));
+				printf("%s%s/%s%s\n", (merged ? GREEN : RED), logatom->CATEGORY, logatom->PN, NORM);
+			}
 		}
+		atom_implode(logatom);
 	}
 
 	free(buf);
@@ -642,9 +642,13 @@ void show_current_emerge(void)
 
 int qlop_main(int argc, char **argv)
 {
-	int i, average = 1;
+	size_t i;
+	int average = 1;
 	char do_time, do_list, do_unlist, do_sync, do_current, do_human_readable = 0;
 	char *logfile = NULL;
+	int flags;
+	depend_atom *atom;
+	DECLARE_ARRAY(atoms);
 
 	do_time = do_list = do_unlist = do_sync = do_current = 0;
 
@@ -672,13 +676,22 @@ int qlop_main(int argc, char **argv)
 
 	argc -= optind;
 	argv += optind;
+	for (i = 0; i < argc; ++i) {
+		atom = atom_explode(argv[i]);
+		if (!atom)
+			warn("invalid atom: %s", argv[i]);
+		else
+			xarraypush_ptr(atoms, atom);
+	}
+
+	flags = 0;
+	if (do_list)
+		flags |= QLOP_LIST;
+	if (do_unlist)
+		flags |= QLOP_UNLIST;
+	if (flags)
+		show_emerge_history(flags, atoms, logfile);
 
-	if (do_list && do_unlist)
-		show_emerge_history(QLOP_LIST | QLOP_UNLIST, argc, argv, logfile);
-	else if (do_list)
-		show_emerge_history(QLOP_LIST, argc, argv, logfile);
-	else if (do_unlist)
-		show_emerge_history(QLOP_UNLIST, argc, argv, logfile);
 	if (do_current)
 		show_current_emerge();
 	if (do_sync)
@@ -689,6 +702,9 @@ int qlop_main(int argc, char **argv)
 			show_merge_times(argv[i], logfile, average, do_human_readable);
 	}
 
+	array_for_each(atoms, i, atom)
+		atom_implode(atom);
+	xarrayfree_int(atoms);
 	free(logfile);
 
 	return EXIT_SUCCESS;


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2016-12-29  2:25 Mike Frysinger
  0 siblings, 0 replies; 23+ messages in thread
From: Mike Frysinger @ 2016-12-29  2:25 UTC (permalink / raw
  To: gentoo-commits

commit:     b06656ffb20e9dc6da0af92388e0af94e2edac49
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Wed Dec 28 22:48:44 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Wed Dec 28 22:48:44 2016 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b06656ff

start some likely/unlikely helpers

 libq/xasprintf.c | 2 +-
 libq/xchdir.c    | 2 +-
 libq/xgetcwd.c   | 2 +-
 libq/xmalloc.c   | 8 ++++----
 libq/xmkdir.c    | 2 +-
 libq/xreadlink.c | 2 +-
 libq/xregex.c    | 4 ++--
 libq/xstrdup.c   | 2 +-
 libq/xsystem.c   | 2 +-
 porting.h        | 3 +++
 10 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/libq/xasprintf.c b/libq/xasprintf.c
index f2f1c58..160223e 100644
--- a/libq/xasprintf.c
+++ b/libq/xasprintf.c
@@ -25,7 +25,7 @@
 #define xasprintf(strp, fmt, args...) \
 	({ \
 		int _ret = asprintf(strp, fmt , ## args); \
-		if (_ret == -1) \
+		if (unlikely(_ret == -1)) \
 			err("Out of memory"); \
 		_ret; \
 	})

diff --git a/libq/xchdir.c b/libq/xchdir.c
index b127e9c..242b04a 100644
--- a/libq/xchdir.c
+++ b/libq/xchdir.c
@@ -10,6 +10,6 @@
 void xchdir(const char *path);
 void xchdir(const char *path)
 {
-	if (chdir(path))
+	if (unlikely(chdir(path) != 0))
 		errp("chdir(%s) failed", path);
 }

diff --git a/libq/xgetcwd.c b/libq/xgetcwd.c
index 876e17c..31f531d 100644
--- a/libq/xgetcwd.c
+++ b/libq/xgetcwd.c
@@ -11,7 +11,7 @@ char *xgetcwd(char *buf, size_t size);
 char *xgetcwd(char *buf, size_t size)
 {
 	char *ret = getcwd(buf, size);
-	if (!ret)
+	if (unlikely(ret == NULL))
 		errp("getcwd() failed");
 	return ret;
 }

diff --git a/libq/xmalloc.c b/libq/xmalloc.c
index 207a15a..9a9173d 100644
--- a/libq/xmalloc.c
+++ b/libq/xmalloc.c
@@ -30,7 +30,7 @@
 static void *xmalloc(size_t size)
 {
 	void *ptr = malloc(size);
-	if (ptr == NULL)
+	if (unlikely(ptr == NULL))
 		err("Out of memory");
 	return ptr;
 }
@@ -38,7 +38,7 @@ static void *xmalloc(size_t size)
 static void *xcalloc(size_t nmemb, size_t size)
 {
 	void *ptr = calloc(nmemb, size);
-	if (ptr == NULL)
+	if (unlikely(ptr == NULL))
 		err("Out of memory");
 	return ptr;
 }
@@ -46,7 +46,7 @@ static void *xcalloc(size_t nmemb, size_t size)
 static void *xzalloc(size_t size)
 {
 	void *ptr = xmalloc(size);
-	if (ptr == NULL)
+	if (unlikely(ptr == NULL))
 		err("Out of memory");
 	memset(ptr, 0x00, size);
 	return ptr;
@@ -55,7 +55,7 @@ static void *xzalloc(size_t size)
 static void *xrealloc(void *optr, size_t size)
 {
 	void *ptr = realloc(optr, size);
-	if (ptr == NULL)
+	if (unlikely(ptr == NULL))
 		err("Out of memory");
 	return ptr;
 }

diff --git a/libq/xmkdir.c b/libq/xmkdir.c
index cc428aa..b47d44c 100644
--- a/libq/xmkdir.c
+++ b/libq/xmkdir.c
@@ -62,7 +62,7 @@ _q_static int rm_rf_at(int dfd, const char *path)
 		if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
 			continue;
 		if (unlinkat(subdfd, de->d_name, 0) == -1) {
-			if (errno != EISDIR)
+			if (unlikely(errno != EISDIR))
 				errp("could not unlink %s", de->d_name);
 			rm_rf_at(subdfd, de->d_name);
 			unlinkat(subdfd, de->d_name, AT_REMOVEDIR);

diff --git a/libq/xreadlink.c b/libq/xreadlink.c
index b580dbd..872264f 100644
--- a/libq/xreadlink.c
+++ b/libq/xreadlink.c
@@ -11,7 +11,7 @@ ssize_t xreadlink(const char *path, char *buf, size_t bufsiz);
 ssize_t xreadlink(const char *path, char *buf, size_t bufsiz)
 {
 	ssize_t ret = readlink(path, buf, bufsiz);
-	if (ret == -1)
+	if (unlikely(ret == -1))
 		errp("readlink(%s) failed", path);
 	return ret;
 }

diff --git a/libq/xregex.c b/libq/xregex.c
index 65f0d47..7df928a 100644
--- a/libq/xregex.c
+++ b/libq/xregex.c
@@ -1,7 +1,7 @@
 static int wregcomp(regex_t *preg, const char *regex, int cflags)
 {
 	int ret = regcomp(preg, regex, cflags);
-	if (ret) {
+	if (unlikely(ret)) {
 		char errbuf[256];
 		regerror(ret, preg, errbuf, sizeof(errbuf));
 		warn("invalid regexp: %s -- %s\n", regex, errbuf);
@@ -11,6 +11,6 @@ static int wregcomp(regex_t *preg, const char *regex, int cflags)
 
 static void xregcomp(regex_t *preg, const char *regex, int cflags)
 {
-	if (wregcomp(preg, regex, cflags))
+	if (unlikely(wregcomp(preg, regex, cflags)))
 		exit(EXIT_FAILURE);
 }

diff --git a/libq/xstrdup.c b/libq/xstrdup.c
index dd2c039..6924d21 100644
--- a/libq/xstrdup.c
+++ b/libq/xstrdup.c
@@ -35,7 +35,7 @@ static char *xstrdup(const char *s)
 		return NULL;
 
 	t = strdup(s);
-	if (t == NULL)
+	if (unlikely(t == NULL))
 		err("Out of memory");
 
 	return t;

diff --git a/libq/xsystem.c b/libq/xsystem.c
index 71e8306..b4af651 100644
--- a/libq/xsystem.c
+++ b/libq/xsystem.c
@@ -10,7 +10,7 @@
 
 static void xsystem(const char *command)
 {
-	if (system(command))
+	if (unlikely(system(command)))
 		errp("system(%s) failed", command);
 }
 

diff --git a/porting.h b/porting.h
index b166bc1..206c6e3 100644
--- a/porting.h
+++ b/porting.h
@@ -77,4 +77,7 @@
 #define CONFIG_EPREFIX "/"
 #endif
 
+#define likely(x) __builtin_expect((x), 1)
+#define unlikely(x) __builtin_expect((x), 0)
+
 #endif


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2016-12-29  2:25 Mike Frysinger
  0 siblings, 0 replies; 23+ messages in thread
From: Mike Frysinger @ 2016-12-29  2:25 UTC (permalink / raw
  To: gentoo-commits

commit:     ec10bc915b138dc729ee42faf152d2ae0a63331a
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Wed Dec 28 23:33:17 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Wed Dec 28 23:33:17 2016 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=ec10bc91

libq: drop unused xgetcwd/xreadlink helpers

 .depend          | 13 ++++++-------
 Makefile.am      |  2 --
 libq/libq.c      |  2 --
 libq/xgetcwd.c   | 17 -----------------
 libq/xreadlink.c | 17 -----------------
 5 files changed, 6 insertions(+), 45 deletions(-)

diff --git a/.depend b/.depend
index 3b63d1f..d824273 100644
--- a/.depend
+++ b/.depend
@@ -2,10 +2,9 @@ main.o: main.c porting.h main.h libq/libq.c libq/busybox.h libq/i18n.h \
  libq/libq.h libq/colors.c libq/xmalloc.c libq/xstrdup.c libq/xasprintf.c \
  libq/hash_fd.c libq/md5_sha1_sum.c libq/human_readable.c libq/rmspace.c \
  libq/compat.c libq/copy_file.c libq/safe_io.c libq/xchdir.c \
- libq/xgetcwd.c libq/xmkdir.c libq/xreadlink.c libq/xregex.c \
- libq/xsystem.c libq/xarray.c libq/atom_explode.c libq/atom_compare.c \
- libq/basename.c libq/scandirat.c libq/prelink.c libq/profile.c \
- libq/vdb.c libq/vdb_get_next_dir.c libq/virtuals.c applets.h \
- include_applets.h q.c qcheck.c qdepends.c qfile.c qlist.c qlop.c \
- qsearch.c qsize.c qtbz2.c quse.c qxpak.c qpkg.c qgrep.c qatom.c qmerge.c \
- qcache.c qglsa.c
+ libq/xmkdir.c libq/xregex.c libq/xsystem.c libq/xarray.c \
+ libq/atom_explode.c libq/atom_compare.c libq/basename.c libq/scandirat.c \
+ libq/prelink.c libq/profile.c libq/vdb.c libq/vdb_get_next_dir.c \
+ libq/virtuals.c applets.h include_applets.h q.c qcheck.c qdepends.c \
+ qfile.c qlist.c qlop.c qsearch.c qsize.c qtbz2.c quse.c qxpak.c qpkg.c \
+ qgrep.c qatom.c qmerge.c qcache.c qglsa.c

diff --git a/Makefile.am b/Makefile.am
index 7b9c35b..7d4a301 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -122,10 +122,8 @@ EXTRA_DIST += \
 	libq/xarray.c \
 	libq/xasprintf.c \
 	libq/xchdir.c \
-	libq/xgetcwd.c \
 	libq/xmalloc.c \
 	libq/xmkdir.c \
-	libq/xreadlink.c \
 	libq/xregex.c \
 	libq/xstrdup.c \
 	libq/xsystem.c \

diff --git a/libq/libq.c b/libq/libq.c
index 5c6eb5c..28fe5d1 100644
--- a/libq/libq.c
+++ b/libq/libq.c
@@ -22,9 +22,7 @@
 #include "copy_file.c"
 #include "safe_io.c"
 #include "xchdir.c"
-#include "xgetcwd.c"
 #include "xmkdir.c"
-#include "xreadlink.c"
 #include "xregex.c"
 #include "xsystem.c"
 #include "xarray.c"

diff --git a/libq/xgetcwd.c b/libq/xgetcwd.c
deleted file mode 100644
index 31f531d..0000000
--- a/libq/xgetcwd.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * utility funcs
- *
- * Copyright 2005-2014 Gentoo Foundation
- * Distributed under the terms of the GNU General Public License v2
- */
-
-#include <unistd.h>
-
-char *xgetcwd(char *buf, size_t size);
-char *xgetcwd(char *buf, size_t size)
-{
-	char *ret = getcwd(buf, size);
-	if (unlikely(ret == NULL))
-		errp("getcwd() failed");
-	return ret;
-}

diff --git a/libq/xreadlink.c b/libq/xreadlink.c
deleted file mode 100644
index 872264f..0000000
--- a/libq/xreadlink.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * utility funcs
- *
- * Copyright 2005-2014 Gentoo Foundation
- * Distributed under the terms of the GNU General Public License v2
- */
-
-#include <unistd.h>
-
-ssize_t xreadlink(const char *path, char *buf, size_t bufsiz);
-ssize_t xreadlink(const char *path, char *buf, size_t bufsiz)
-{
-	ssize_t ret = readlink(path, buf, bufsiz);
-	if (unlikely(ret == -1))
-		errp("readlink(%s) failed", path);
-	return ret;
-}


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2018-05-18 16:58 Fabian Groffen
  0 siblings, 0 replies; 23+ messages in thread
From: Fabian Groffen @ 2018-05-18 16:58 UTC (permalink / raw
  To: gentoo-commits

commit:     c144d46a11bbac0dff31ca4278c65502da5f4b1b
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri May 18 15:51:42 2018 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri May 18 15:51:42 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=c144d46a

add fall through comments for gcc-7

 libq/vdb.c | 1 +
 qlist.c    | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/libq/vdb.c b/libq/vdb.c
index 85f061a..fa4f6ce 100644
--- a/libq/vdb.c
+++ b/libq/vdb.c
@@ -103,6 +103,7 @@ q_vdb_filter_cat(const struct dirent *de)
 				case '-':
 					if (i)
 						break;
+					/* fall through */
 				default:
 					return 0;
 			}

diff --git a/qlist.c b/qlist.c
index 4d3a4e0..a332acc 100644
--- a/qlist.c
+++ b/qlist.c
@@ -389,7 +389,7 @@ int qlist_main(int argc, char **argv)
 	while ((i = GETOPT_LONG(QLIST, qlist, "")) != -1) {
 		switch (i) {
 		COMMON_GETOPTS_CASES(qlist)
-		case 'a': state.all = true;
+		case 'a': state.all = true; /* fall through */
 		case 'I': state.just_pkgname = true; break;
 		case 'S': state.just_pkgname = true; ++state.show_slots; break;
 		case 'R': state.just_pkgname = state.show_repo = true; break;


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2019-05-02 15:48 Fabian Groffen
  0 siblings, 0 replies; 23+ messages in thread
From: Fabian Groffen @ 2019-05-02 15:48 UTC (permalink / raw
  To: gentoo-commits

commit:     35d7272b07fbbdc21c13b963e042aaf62481430a
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu May  2 15:46:37 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu May  2 15:46:37 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=35d7272b

libq/cache: implement escape processing in cache_read_file_ebuild

- replace escapes (\\ -> \, \" -> ")
- replace line-continuation escape+nl by space

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 TODO.md      |  6 ++----
 libq/cache.c | 36 +++++++++++++++++++++++++-----------
 2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/TODO.md b/TODO.md
index 3a3c26a..9d44710 100644
--- a/TODO.md
+++ b/TODO.md
@@ -11,14 +11,14 @@
 - multiline reads don't yet work for quse/qsearch
 
 - standardize/unify/clean up misc handling of colors
+  define rules:
+    BOLD CATEGORY/ BLUE PKG GREEN ::REPO NORM [ MAGENTA USE NORM ]
 
 - remove odd rmspace for each string in libq/set.c (allows a lot less
   malloc/frees)
 
 - make set.c to array (xarray) instead of C-array (list)
 
-- equiv of `equery m` (metadata)
-
 - env vars only get expanded once, so this fails:<br>
   `ACCEPT_LICENSE="foo"`<br>
   `ACCEPT_LICENSE="${ACCEPT_LICENSE} bar"`<br>
@@ -30,8 +30,6 @@
 
 - vdb repo/slot think about when it is freed (see cache\_pkg\_close)
 
-- cache:cache\_read\_file\_ebuild deal with \\\\n sequences
-
 - qcache -> rename to qkeyword
 
 - quse -K -> move to qkeyword

diff --git a/libq/cache.c b/libq/cache.c
index ee3a47c..9993002 100644
--- a/libq/cache.c
+++ b/libq/cache.c
@@ -370,8 +370,9 @@ cache_read_file_ebuild(cache_pkg_ctx *pkg_ctx)
 	size_t len;
 	char *p;
 	char *q;
-	char *r;
+	char *w;
 	char **key;
+	bool esc;
 	bool findnl;
 
 	if ((f = fdopen(pkg_ctx->fd, "r")) == NULL)
@@ -422,22 +423,35 @@ cache_read_file_ebuild(cache_pkg_ctx *pkg_ctx)
 			if (*q == '"' || *q == '\'') {
 				/* find matching quote */
 				p++;
+				w = p;
+				esc = false;
 				do {
-					while (*p != '\0' && *p != *q)
-						p++;
-					if (*p == *q) {
-						for (r = p - 1; r > q; r--)
-							if (*r != '\\')
-								break;
-						if (r != q && (p - 1 - r) % 2 == 1) {
-							/* escaped, move along */
-							p++;
-							continue;
+					while (*p != '\0' && *p != *q) {
+						if (*p == '\\') {
+							esc = !esc;
+							if (esc) {
+								p++;
+								continue;
+							}
+						} else {
+							/* implement line continuation (\ before newline) */
+							if (esc && (*p == '\n' || *p == '\r'))
+								*p = ' ';
+							esc = false;
 						}
+
+						*w++ = *p++;
+					}
+					if (*p == *q && esc) {
+						/* escaped, move along */
+						esc = false;
+						*w++ = *p++;
+						continue;
 					}
 					break;
 				} while (1);
 				q++;
+				*w = '\0';
 			} else {
 				/* find first whitespace */
 				while (!isspace((int)*p))


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2019-05-06 17:33 Fabian Groffen
  0 siblings, 0 replies; 23+ messages in thread
From: Fabian Groffen @ 2019-05-06 17:33 UTC (permalink / raw
  To: gentoo-commits

commit:     d87d181cd692247a5a7411fd6284c862bc73f28b
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon May  6 17:31:29 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon May  6 17:31:29 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=d87d181c

libq/vdb: drop q_ prefix

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 TODO.md      |   2 +-
 libq/cache.c |  40 +++++++++----------
 libq/cache.h |   6 +--
 libq/vdb.c   | 127 ++++++++++++++++++++++++++++++-----------------------------
 libq/vdb.h   |  74 +++++++++++++++++-----------------
 qcheck.c     |  10 ++---
 qdepends.c   |   8 ++--
 qfile.c      |  10 ++---
 qgrep.c      |   4 +-
 qlist.c      |  24 +++++------
 qmerge.c     |  48 +++++++++++-----------
 qpkg.c       |  14 +++----
 qsize.c      |   6 +--
 13 files changed, 187 insertions(+), 186 deletions(-)

diff --git a/TODO.md b/TODO.md
index bc4f524..6fda56d 100644
--- a/TODO.md
+++ b/TODO.md
@@ -23,7 +23,7 @@
   we end up getting just:<br>
   `ACCEPT_LICENSE=" bar"`
 
-- q\_vdb\_foreach\_pkg should have variant that takes an atom (or just
+- vdb\_foreach\_pkg should have variant that takes an atom (or just
   cat?) to reduce search space, same for cache\_foreach\_pkg
 
 - vdb repo/slot think about when it is freed (see cache\_pkg\_close)

diff --git a/libq/cache.c b/libq/cache.c
index c0ea85e..304cd34 100644
--- a/libq/cache.c
+++ b/libq/cache.c
@@ -66,7 +66,7 @@ cache_open(const char *sroot, const char *portdir)
 	}
 
 	snprintf(buf, sizeof(buf), "%s/%s", portdir, portcachedir_md5);
-	ret = q_vdb_open2(sroot, buf, true);
+	ret = vdb_open2(sroot, buf, true);
 	if (ret != NULL) {
 		ret->cachetype = CACHE_METADATA_MD5;
 		ret->repo = repo;
@@ -74,14 +74,14 @@ cache_open(const char *sroot, const char *portdir)
 	}
 
 	snprintf(buf, sizeof(buf), "%s/%s", portdir, portcachedir_pms);
-	ret = q_vdb_open2(sroot, buf, true);
+	ret = vdb_open2(sroot, buf, true);
 	if (ret != NULL) {
 		ret->cachetype = CACHE_METADATA_PMS;
 		ret->repo = repo;
 		return ret;
 	}
 
-	ret = q_vdb_open2(sroot, portdir, true);
+	ret = vdb_open2(sroot, portdir, true);
 	if (ret != NULL) {
 		ret->cachetype = CACHE_EBUILD;
 		ret->repo = repo;
@@ -101,31 +101,31 @@ cache_close(cache_ctx *ctx)
 		free(ctx->repo);
 	if (ctx->ebuilddir_ctx != NULL)
 		free(ctx->ebuilddir_ctx);
-	q_vdb_close(ctx);
+	vdb_close(ctx);
 }
 
 cache_cat_ctx *
 cache_open_cat(cache_ctx *ctx, const char *name)
 {
-	return q_vdb_open_cat(ctx, name);
+	return vdb_open_cat(ctx, name);
 }
 
 cache_cat_ctx *
 cache_next_cat(cache_ctx *ctx)
 {
-	return q_vdb_next_cat(ctx);
+	return vdb_next_cat(ctx);
 }
 
 void
 cache_close_cat(cache_cat_ctx *cat_ctx)
 {
-	return q_vdb_close_cat(cat_ctx);
+	return vdb_close_cat(cat_ctx);
 }
 
 cache_pkg_ctx *
 cache_open_pkg(cache_cat_ctx *cat_ctx, const char *name)
 {
-	return q_vdb_open_pkg(cat_ctx, name);
+	return vdb_open_pkg(cat_ctx, name);
 }
 
 cache_pkg_ctx *
@@ -141,13 +141,13 @@ cache_next_pkg(cache_cat_ctx *cat_ctx)
 		 * to CAT/P like in VDB and metadata */
 		do {
 			if (ctx->ebuilddir_pkg_ctx == NULL) {
-				q_vdb_ctx *pkgdir = ctx->ebuilddir_ctx;
+				vdb_ctx *pkgdir = ctx->ebuilddir_ctx;
 
 				if (pkgdir == NULL)
-					pkgdir = ctx->ebuilddir_ctx = xmalloc(sizeof(q_vdb_ctx));
+					pkgdir = ctx->ebuilddir_ctx = xmalloc(sizeof(vdb_ctx));
 				memset(ctx->ebuilddir_ctx, '\0', sizeof(*ctx->ebuilddir_ctx));
 
-				if ((ctx->ebuilddir_pkg_ctx = q_vdb_next_pkg(cat_ctx)) == NULL)
+				if ((ctx->ebuilddir_pkg_ctx = vdb_next_pkg(cat_ctx)) == NULL)
 					return NULL;
 
 				pkgdir->portroot_fd = -1;
@@ -159,7 +159,7 @@ cache_next_pkg(cache_cat_ctx *cat_ctx)
 				pkgdir->cachetype = ctx->cachetype;
 
 				ctx->ebuilddir_cat_ctx =
-					q_vdb_open_cat(pkgdir, ctx->ebuilddir_pkg_ctx->name);
+					vdb_open_cat(pkgdir, ctx->ebuilddir_pkg_ctx->name);
 
 				/* opening might fail if what we found wasn't a
 				 * directory or something */
@@ -172,9 +172,9 @@ cache_next_pkg(cache_cat_ctx *cat_ctx)
 				ctx->ebuilddir_cat_ctx->name = cat_ctx->name;
 			}
 
-			ret = q_vdb_next_pkg(ctx->ebuilddir_cat_ctx);
+			ret = vdb_next_pkg(ctx->ebuilddir_cat_ctx);
 			if (ret == NULL) {
-				q_vdb_close_cat(ctx->ebuilddir_cat_ctx);
+				vdb_close_cat(ctx->ebuilddir_cat_ctx);
 				ctx->ebuilddir_pkg_ctx = NULL;
 			} else {
 				if ((p = strstr(ret->name, ".ebuild")) == NULL) {
@@ -186,7 +186,7 @@ cache_next_pkg(cache_cat_ctx *cat_ctx)
 			}
 		} while (ret == NULL);
 	} else {
-		ret = q_vdb_next_pkg(cat_ctx);
+		ret = vdb_next_pkg(cat_ctx);
 	}
 
 	return ret;
@@ -627,16 +627,16 @@ cache_close_metadata(cache_metadata_xml *meta_ctx)
 void
 cache_close_pkg(cache_pkg_ctx *pkg_ctx)
 {
-	/* avoid free of cache_ctx' repo by q_vdb_close_pkg */
+	/* avoid free of cache_ctx' repo by vdb_close_pkg */
 	if (pkg_ctx->cat_ctx->ctx->repo == pkg_ctx->repo)
 		pkg_ctx->repo = NULL;
 
-	q_vdb_close_pkg(pkg_ctx);
+	vdb_close_pkg(pkg_ctx);
 }
 
 static int
 cache_foreach_pkg_int(const char *sroot, const char *portdir,
-		q_vdb_pkg_cb callback, void *priv, q_vdb_cat_filter filter,
+		vdb_pkg_cb callback, void *priv, vdb_cat_filter filter,
 		bool sort, void *catsortfunc, void *pkgsortfunc)
 {
 	cache_ctx *ctx;
@@ -671,7 +671,7 @@ cache_foreach_pkg_int(const char *sroot, const char *portdir,
 
 int
 cache_foreach_pkg(const char *sroot, const char *portdir,
-		q_vdb_pkg_cb callback, void *priv, q_vdb_cat_filter filter)
+		vdb_pkg_cb callback, void *priv, vdb_cat_filter filter)
 {
 	return cache_foreach_pkg_int(sroot, portdir, callback, priv,
 			filter, false, NULL, NULL);
@@ -679,7 +679,7 @@ cache_foreach_pkg(const char *sroot, const char *portdir,
 
 int
 cache_foreach_pkg_sorted(const char *sroot, const char *portdir,
-		q_vdb_pkg_cb callback, void *priv,
+		vdb_pkg_cb callback, void *priv,
 		void *catsortfunc, void *pkgsortfunc)
 {
 	return cache_foreach_pkg_int(sroot, portdir, callback, priv,

diff --git a/libq/cache.h b/libq/cache.h
index 2ad2e78..e863daf 100644
--- a/libq/cache.h
+++ b/libq/cache.h
@@ -13,9 +13,9 @@
 #include "atom.h"
 #include "vdb.h"
 
-#define cache_ctx     q_vdb_ctx
-#define cache_cat_ctx q_vdb_cat_ctx
-#define cache_pkg_ctx q_vdb_pkg_ctx
+#define cache_ctx     vdb_ctx
+#define cache_cat_ctx vdb_cat_ctx
+#define cache_pkg_ctx vdb_pkg_ctx
 
 typedef struct {
 	char *_data;

diff --git a/libq/vdb.c b/libq/vdb.c
index 034a28c..5dc5e79 100644
--- a/libq/vdb.c
+++ b/libq/vdb.c
@@ -18,10 +18,10 @@
 #include <ctype.h>
 #include <xalloc.h>
 
-q_vdb_ctx *
-q_vdb_open2(const char *sroot, const char *svdb, bool quiet)
+vdb_ctx *
+vdb_open2(const char *sroot, const char *svdb, bool quiet)
 {
-	q_vdb_ctx *ctx = xmalloc(sizeof(*ctx));
+	vdb_ctx *ctx = xmalloc(sizeof(*ctx));
 
 	ctx->portroot_fd = open(sroot, O_RDONLY|O_CLOEXEC|O_PATH);
 	if (ctx->portroot_fd == -1) {
@@ -64,14 +64,14 @@ q_vdb_open2(const char *sroot, const char *svdb, bool quiet)
 	return NULL;
 }
 
-q_vdb_ctx *
-q_vdb_open(const char *sroot, const char *svdb)
+vdb_ctx *
+vdb_open(const char *sroot, const char *svdb)
 {
-	return q_vdb_open2(sroot, svdb, false);
+	return vdb_open2(sroot, svdb, false);
 }
 
 void
-q_vdb_close(q_vdb_ctx *ctx)
+vdb_close(vdb_ctx *ctx)
 {
 	closedir(ctx->dir);
 	/* closedir() above does this for us: */
@@ -83,7 +83,7 @@ q_vdb_close(q_vdb_ctx *ctx)
 }
 
 int
-q_vdb_filter_cat(const struct dirent *de)
+vdb_filter_cat(const struct dirent *de)
 {
 	int i;
 	bool founddash;
@@ -124,10 +124,10 @@ q_vdb_filter_cat(const struct dirent *de)
 	return i;
 }
 
-q_vdb_cat_ctx *
-q_vdb_open_cat(q_vdb_ctx *ctx, const char *name)
+vdb_cat_ctx *
+vdb_open_cat(vdb_ctx *ctx, const char *name)
 {
-	q_vdb_cat_ctx *cat_ctx;
+	vdb_cat_ctx *cat_ctx;
 	int fd;
 	DIR *dir;
 
@@ -151,21 +151,21 @@ q_vdb_open_cat(q_vdb_ctx *ctx, const char *name)
 	return cat_ctx;
 }
 
-q_vdb_cat_ctx *
-q_vdb_next_cat(q_vdb_ctx *ctx)
+vdb_cat_ctx *
+vdb_next_cat(vdb_ctx *ctx)
 {
 	/* search for a category directory */
-	q_vdb_cat_ctx *cat_ctx = NULL;
+	vdb_cat_ctx *cat_ctx = NULL;
 
 	if (ctx->do_sort) {
 		if (ctx->cat_de == NULL) {
 			ctx->cat_cnt = scandirat(ctx->vdb_fd,
-					".", &ctx->cat_de, q_vdb_filter_cat, ctx->catsortfunc);
+					".", &ctx->cat_de, vdb_filter_cat, ctx->catsortfunc);
 			ctx->cat_cur = 0;
 		}
 
 		while (ctx->cat_cur < ctx->cat_cnt) {
-			cat_ctx = q_vdb_open_cat(ctx, ctx->cat_de[ctx->cat_cur++]->d_name);
+			cat_ctx = vdb_open_cat(ctx, ctx->cat_de[ctx->cat_cur++]->d_name);
 			if (!cat_ctx)
 				continue;
 			break;
@@ -178,10 +178,10 @@ q_vdb_next_cat(q_vdb_ctx *ctx)
 			if (!de)
 				break;
 
-			if (q_vdb_filter_cat(de) == 0)
+			if (vdb_filter_cat(de) == 0)
 				continue;
 
-			cat_ctx = q_vdb_open_cat(ctx, de->d_name);
+			cat_ctx = vdb_open_cat(ctx, de->d_name);
 			if (!cat_ctx)
 				continue;
 
@@ -193,7 +193,7 @@ q_vdb_next_cat(q_vdb_ctx *ctx)
 }
 
 void
-q_vdb_close_cat(q_vdb_cat_ctx *cat_ctx)
+vdb_close_cat(vdb_cat_ctx *cat_ctx)
 {
 	closedir(cat_ctx->dir);
 	/* closedir() above does this for us: */
@@ -204,7 +204,7 @@ q_vdb_close_cat(q_vdb_cat_ctx *cat_ctx)
 }
 
 int
-q_vdb_filter_pkg(const struct dirent *de)
+vdb_filter_pkg(const struct dirent *de)
 {
 	int i;
 	bool founddash = false;
@@ -235,33 +235,34 @@ q_vdb_filter_pkg(const struct dirent *de)
 	return i;
 }
 
-q_vdb_pkg_ctx *
-q_vdb_open_pkg(q_vdb_cat_ctx *cat_ctx, const char *name)
+vdb_pkg_ctx *
+vdb_open_pkg(vdb_cat_ctx *cat_ctx, const char *name)
 {
-	q_vdb_pkg_ctx *pkg_ctx = xmalloc(sizeof(*pkg_ctx));
+	vdb_pkg_ctx *pkg_ctx = xmalloc(sizeof(*pkg_ctx));
 	pkg_ctx->name = name;
 	pkg_ctx->slot = NULL;
 	pkg_ctx->repo = cat_ctx->ctx->repo;
 	pkg_ctx->fd = -1;
 	pkg_ctx->cat_ctx = cat_ctx;
+	pkg_ctx->atom = NULL;
 	return pkg_ctx;
 }
 
-q_vdb_pkg_ctx *
-q_vdb_next_pkg(q_vdb_cat_ctx *cat_ctx)
+vdb_pkg_ctx *
+vdb_next_pkg(vdb_cat_ctx *cat_ctx)
 {
-	q_vdb_pkg_ctx *pkg_ctx = NULL;
+	vdb_pkg_ctx *pkg_ctx = NULL;
 
 	if (cat_ctx->ctx->do_sort) {
 		if (cat_ctx->pkg_de == NULL) {
 			cat_ctx->pkg_cnt = scandirat(cat_ctx->fd, ".", &cat_ctx->pkg_de,
-					q_vdb_filter_pkg, cat_ctx->ctx->pkgsortfunc);
+					vdb_filter_pkg, cat_ctx->ctx->pkgsortfunc);
 			cat_ctx->pkg_cur = 0;
 		}
 
 		while (cat_ctx->pkg_cur < cat_ctx->pkg_cnt) {
 			pkg_ctx =
-				q_vdb_open_pkg(cat_ctx,
+				vdb_open_pkg(cat_ctx,
 						cat_ctx->pkg_de[cat_ctx->pkg_cur++]->d_name);
 			if (!pkg_ctx)
 				continue;
@@ -274,10 +275,10 @@ q_vdb_next_pkg(q_vdb_cat_ctx *cat_ctx)
 			if (!de)
 				break;
 
-			if (q_vdb_filter_pkg(de) == 0)
+			if (vdb_filter_pkg(de) == 0)
 				continue;
 
-			pkg_ctx = q_vdb_open_pkg(cat_ctx, de->d_name);
+			pkg_ctx = vdb_open_pkg(cat_ctx, de->d_name);
 			if (!pkg_ctx)
 				continue;
 
@@ -289,7 +290,7 @@ q_vdb_next_pkg(q_vdb_cat_ctx *cat_ctx)
 }
 
 int
-q_vdb_pkg_openat(q_vdb_pkg_ctx *pkg_ctx, const char *file, int flags, mode_t mode)
+vdb_pkg_openat(vdb_pkg_ctx *pkg_ctx, const char *file, int flags, mode_t mode)
 {
 	if (pkg_ctx->fd == -1) {
 		pkg_ctx->fd = openat(pkg_ctx->cat_ctx->fd, pkg_ctx->name,
@@ -302,13 +303,13 @@ q_vdb_pkg_openat(q_vdb_pkg_ctx *pkg_ctx, const char *file, int flags, mode_t mod
 }
 
 FILE *
-q_vdb_pkg_fopenat(q_vdb_pkg_ctx *pkg_ctx, const char *file,
+vdb_pkg_fopenat(vdb_pkg_ctx *pkg_ctx, const char *file,
 	int flags, mode_t mode, const char *fmode)
 {
 	FILE *fp;
 	int fd;
 
-	fd = q_vdb_pkg_openat(pkg_ctx, file, flags, mode);
+	fd = vdb_pkg_openat(pkg_ctx, file, flags, mode);
 	if (fd == -1)
 		return NULL;
 
@@ -320,9 +321,9 @@ q_vdb_pkg_fopenat(q_vdb_pkg_ctx *pkg_ctx, const char *file,
 }
 
 bool
-q_vdb_pkg_eat(q_vdb_pkg_ctx *pkg_ctx, const char *file, char **bufptr, size_t *buflen)
+vdb_pkg_eat(vdb_pkg_ctx *pkg_ctx, const char *file, char **bufptr, size_t *buflen)
 {
-	int fd = q_vdb_pkg_openat(pkg_ctx, file, O_RDONLY, 0);
+	int fd = vdb_pkg_openat(pkg_ctx, file, O_RDONLY, 0);
 	bool ret = eat_file_fd(fd, bufptr, buflen);
 	rmspace(*bufptr);
 	if (fd != -1)
@@ -331,7 +332,7 @@ q_vdb_pkg_eat(q_vdb_pkg_ctx *pkg_ctx, const char *file, char **bufptr, size_t *b
 }
 
 void
-q_vdb_close_pkg(q_vdb_pkg_ctx *pkg_ctx)
+vdb_close_pkg(vdb_pkg_ctx *pkg_ctx)
 {
 	if (pkg_ctx->fd != -1)
 		close(pkg_ctx->fd);
@@ -343,16 +344,16 @@ q_vdb_close_pkg(q_vdb_pkg_ctx *pkg_ctx)
 }
 
 static int
-q_vdb_foreach_pkg_int(const char *sroot, const char *svdb,
-		q_vdb_pkg_cb callback, void *priv, q_vdb_cat_filter filter,
+vdb_foreach_pkg_int(const char *sroot, const char *svdb,
+		vdb_pkg_cb callback, void *priv, vdb_cat_filter filter,
 		bool sort, void *catsortfunc, void *pkgsortfunc)
 {
-	q_vdb_ctx *ctx;
-	q_vdb_cat_ctx *cat_ctx;
-	q_vdb_pkg_ctx *pkg_ctx;
+	vdb_ctx *ctx;
+	vdb_cat_ctx *cat_ctx;
+	vdb_pkg_ctx *pkg_ctx;
 	int ret;
 
-	ctx = q_vdb_open(sroot, svdb);
+	ctx = vdb_open(sroot, svdb);
 	if (!ctx)
 		return EXIT_FAILURE;
 
@@ -363,38 +364,38 @@ q_vdb_foreach_pkg_int(const char *sroot, const char *svdb,
 		ctx->pkgsortfunc = pkgsortfunc;
 
 	ret = 0;
-	while ((cat_ctx = q_vdb_next_cat(ctx))) {
+	while ((cat_ctx = vdb_next_cat(ctx))) {
 		if (filter && !filter(cat_ctx, priv))
 			continue;
-		while ((pkg_ctx = q_vdb_next_pkg(cat_ctx))) {
+		while ((pkg_ctx = vdb_next_pkg(cat_ctx))) {
 			ret |= callback(pkg_ctx, priv);
-			q_vdb_close_pkg(pkg_ctx);
+			vdb_close_pkg(pkg_ctx);
 		}
-		q_vdb_close_cat(cat_ctx);
+		vdb_close_cat(cat_ctx);
 	}
-	q_vdb_close(ctx);
+	vdb_close(ctx);
 
 	return ret;
 }
 
 int
-q_vdb_foreach_pkg(const char *sroot, const char *svdb,
-		q_vdb_pkg_cb callback, void *priv, q_vdb_cat_filter filter)
+vdb_foreach_pkg(const char *sroot, const char *svdb,
+		vdb_pkg_cb callback, void *priv, vdb_cat_filter filter)
 {
-	return q_vdb_foreach_pkg_int(sroot, svdb, callback, priv,
+	return vdb_foreach_pkg_int(sroot, svdb, callback, priv,
 			filter, false, NULL, NULL);
 }
 
 int
-q_vdb_foreach_pkg_sorted(const char *sroot, const char *svdb,
-		q_vdb_pkg_cb callback, void *priv)
+vdb_foreach_pkg_sorted(const char *sroot, const char *svdb,
+		vdb_pkg_cb callback, void *priv)
 {
-	return q_vdb_foreach_pkg_int(sroot, svdb, callback, priv,
+	return vdb_foreach_pkg_int(sroot, svdb, callback, priv,
 			NULL, true, NULL, NULL);
 }
 
 struct dirent *
-q_vdb_get_next_dir(DIR *dir)
+vdb_get_next_dir(DIR *dir)
 {
 	/* search for a category directory */
 	struct dirent *ret;
@@ -406,23 +407,23 @@ next_entry:
 		return NULL;
 	}
 
-	if (q_vdb_filter_cat(ret) == 0)
+	if (vdb_filter_cat(ret) == 0)
 		goto next_entry;
 
 	return ret;
 }
 
 depend_atom *
-q_vdb_get_atom(q_vdb_pkg_ctx *pkg_ctx)
+vdb_get_atom(vdb_pkg_ctx *pkg_ctx)
 {
 	pkg_ctx->atom = atom_explode(pkg_ctx->name);
 	if (pkg_ctx->atom == NULL)
 		return NULL;
 	pkg_ctx->atom->CATEGORY = (char *)pkg_ctx->cat_ctx->name;
 
-	q_vdb_pkg_eat(pkg_ctx, "SLOT", &pkg_ctx->slot, &pkg_ctx->slot_len);
+	vdb_pkg_eat(pkg_ctx, "SLOT", &pkg_ctx->slot, &pkg_ctx->slot_len);
 	pkg_ctx->atom->SLOT = pkg_ctx->slot;
-	q_vdb_pkg_eat(pkg_ctx, "repository", &pkg_ctx->repo, &pkg_ctx->repo_len);
+	vdb_pkg_eat(pkg_ctx, "repository", &pkg_ctx->repo, &pkg_ctx->repo_len);
 	pkg_ctx->atom->REPO = pkg_ctx->repo;
 
 	return pkg_ctx->atom;
@@ -431,7 +432,7 @@ q_vdb_get_atom(q_vdb_pkg_ctx *pkg_ctx)
 set *
 get_vdb_atoms(const char *sroot, const char *svdb, int fullcpv)
 {
-	q_vdb_ctx *ctx;
+	vdb_ctx *ctx;
 
 	int cfd, j;
 	int dfd, i;
@@ -447,18 +448,18 @@ get_vdb_atoms(const char *sroot, const char *svdb, int fullcpv)
 	depend_atom *atom = NULL;
 	set *cpf = NULL;
 
-	ctx = q_vdb_open(sroot, svdb);
+	ctx = vdb_open(sroot, svdb);
 	if (!ctx)
 		return NULL;
 
 	/* scan the cat first */
-	cfd = scandirat(ctx->vdb_fd, ".", &cat, q_vdb_filter_cat, alphasort);
+	cfd = scandirat(ctx->vdb_fd, ".", &cat, vdb_filter_cat, alphasort);
 	if (cfd < 0)
 		goto fuckit;
 
 	for (j = 0; j < cfd; j++) {
 		dfd = scandirat(ctx->vdb_fd, cat[j]->d_name,
-				&pf, q_vdb_filter_pkg, alphasort);
+				&pf, vdb_filter_pkg, alphasort);
 		if (dfd < 0)
 			continue;
 		for (i = 0; i < dfd; i++) {
@@ -499,6 +500,6 @@ get_vdb_atoms(const char *sroot, const char *svdb, int fullcpv)
 	scandir_free(cat, cfd);
 
  fuckit:
-	q_vdb_close(ctx);
+	vdb_close(ctx);
 	return cpf;
 }

diff --git a/libq/vdb.h b/libq/vdb.h
index 3cfa95b..2954bef 100644
--- a/libq/vdb.h
+++ b/libq/vdb.h
@@ -11,12 +11,12 @@
 
 #include "set.h"
 
-typedef struct q_vdb_ctx q_vdb_ctx;
-typedef struct q_vdb_cat_ctx q_vdb_cat_ctx;
-typedef struct q_vdb_pkg_ctx q_vdb_pkg_ctx;
+typedef struct vdb_ctx vdb_ctx;
+typedef struct vdb_cat_ctx vdb_cat_ctx;
+typedef struct vdb_pkg_ctx vdb_pkg_ctx;
 
 /* VDB context */
-struct q_vdb_ctx {
+struct vdb_ctx {
 	int portroot_fd;
 	int vdb_fd;
 	DIR *dir;
@@ -33,64 +33,64 @@ struct q_vdb_ctx {
 		CACHE_EBUILD,
 		CACHE_VDB,
 	} cachetype:3;
-	q_vdb_pkg_ctx *ebuilddir_pkg_ctx;
-	q_vdb_cat_ctx *ebuilddir_cat_ctx;
-	q_vdb_ctx *ebuilddir_ctx;
+	vdb_pkg_ctx *ebuilddir_pkg_ctx;
+	vdb_cat_ctx *ebuilddir_cat_ctx;
+	vdb_ctx *ebuilddir_ctx;
 	char *repo;
 };
 
 /* Category context */
-struct q_vdb_cat_ctx {
+struct vdb_cat_ctx {
 	const char *name;
 	int fd;
 	DIR *dir;
-	const q_vdb_ctx *ctx;
+	const vdb_ctx *ctx;
 	struct dirent **pkg_de;
 	size_t pkg_cnt;
 	size_t pkg_cur;
 };
 
 /* Package context */
-struct q_vdb_pkg_ctx {
+struct vdb_pkg_ctx {
 	const char *name;
 	char *slot;
 	char *repo;
 	size_t slot_len;
 	size_t repo_len;
 	int fd;
-	q_vdb_cat_ctx *cat_ctx;
+	vdb_cat_ctx *cat_ctx;
 	depend_atom *atom;
 };
 
 /* Global helpers */
-typedef int (q_vdb_pkg_cb)(q_vdb_pkg_ctx *, void *priv);
-typedef int (q_vdb_cat_filter)(q_vdb_cat_ctx *, void *priv);
+typedef int (vdb_pkg_cb)(vdb_pkg_ctx *, void *priv);
+typedef int (vdb_cat_filter)(vdb_cat_ctx *, void *priv);
 
-q_vdb_ctx *q_vdb_open(const char *sroot, const char *svdb);
-q_vdb_ctx *q_vdb_open2(const char *sroot, const char *svdb, bool quiet);
-void q_vdb_close(q_vdb_ctx *ctx);
-int q_vdb_filter_cat(const struct dirent *de);
-q_vdb_cat_ctx *q_vdb_open_cat(q_vdb_ctx *ctx, const char *name);
-q_vdb_cat_ctx *q_vdb_next_cat(q_vdb_ctx *ctx);
-void q_vdb_close_cat(q_vdb_cat_ctx *cat_ctx);
-int q_vdb_filter_pkg(const struct dirent *de);
-q_vdb_pkg_ctx *q_vdb_open_pkg(q_vdb_cat_ctx *cat_ctx, const char *name);
-q_vdb_pkg_ctx *q_vdb_next_pkg(q_vdb_cat_ctx *cat_ctx);
-int q_vdb_pkg_openat(q_vdb_pkg_ctx *pkg_ctx, const char *file, int flags, mode_t mode);
-FILE *q_vdb_pkg_fopenat(q_vdb_pkg_ctx *pkg_ctx, const char *file,
+vdb_ctx *vdb_open(const char *sroot, const char *svdb);
+vdb_ctx *vdb_open2(const char *sroot, const char *svdb, bool quiet);
+void vdb_close(vdb_ctx *ctx);
+int vdb_filter_cat(const struct dirent *de);
+vdb_cat_ctx *vdb_open_cat(vdb_ctx *ctx, const char *name);
+vdb_cat_ctx *vdb_next_cat(vdb_ctx *ctx);
+void vdb_close_cat(vdb_cat_ctx *cat_ctx);
+int vdb_filter_pkg(const struct dirent *de);
+vdb_pkg_ctx *vdb_open_pkg(vdb_cat_ctx *cat_ctx, const char *name);
+vdb_pkg_ctx *vdb_next_pkg(vdb_cat_ctx *cat_ctx);
+int vdb_pkg_openat(vdb_pkg_ctx *pkg_ctx, const char *file, int flags, mode_t mode);
+FILE *vdb_pkg_fopenat(vdb_pkg_ctx *pkg_ctx, const char *file,
 	int flags, mode_t mode, const char *fmode);
-#define q_vdb_pkg_fopenat_ro(pkg_ctx, file) \
-	q_vdb_pkg_fopenat(pkg_ctx, file, O_RDONLY, 0, "r")
-#define q_vdb_pkg_fopenat_rw(pkg_ctx, file) \
-	q_vdb_pkg_fopenat(pkg_ctx, file, O_RDWR|O_CREAT|O_TRUNC, 0644, "w")
-bool q_vdb_pkg_eat(q_vdb_pkg_ctx *pkg_ctx, const char *file, char **bufptr, size_t *buflen);
-void q_vdb_close_pkg(q_vdb_pkg_ctx *pkg_ctx);
-int q_vdb_foreach_pkg(const char *sroot, const char *svdb,
-		q_vdb_pkg_cb callback, void *priv, q_vdb_cat_filter filter);
-int q_vdb_foreach_pkg_sorted(const char *sroot, const char *svdb,
-		q_vdb_pkg_cb callback, void *priv);
-struct dirent *q_vdb_get_next_dir(DIR *dir);
+#define vdb_pkg_fopenat_ro(pkg_ctx, file) \
+	vdb_pkg_fopenat(pkg_ctx, file, O_RDONLY, 0, "r")
+#define vdb_pkg_fopenat_rw(pkg_ctx, file) \
+	vdb_pkg_fopenat(pkg_ctx, file, O_RDWR|O_CREAT|O_TRUNC, 0644, "w")
+bool vdb_pkg_eat(vdb_pkg_ctx *pkg_ctx, const char *file, char **bufptr, size_t *buflen);
+void vdb_close_pkg(vdb_pkg_ctx *pkg_ctx);
+int vdb_foreach_pkg(const char *sroot, const char *svdb,
+		vdb_pkg_cb callback, void *priv, vdb_cat_filter filter);
+int vdb_foreach_pkg_sorted(const char *sroot, const char *svdb,
+		vdb_pkg_cb callback, void *priv);
+struct dirent *vdb_get_next_dir(DIR *dir);
 set *get_vdb_atoms(const char *sroot, const char *svdb, int fullcpv);
-depend_atom *q_vdb_get_atom(q_vdb_pkg_ctx *pkg_ctx);
+depend_atom *vdb_get_atom(vdb_pkg_ctx *pkg_ctx);
 
 #endif

diff --git a/qcheck.c b/qcheck.c
index 0585396..377a187 100644
--- a/qcheck.c
+++ b/qcheck.c
@@ -65,7 +65,7 @@ struct qcheck_opt_state {
 };
 
 static int
-qcheck_process_contents(q_vdb_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state)
+qcheck_process_contents(vdb_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state)
 {
 	int fd_contents;
 	FILE *fp_contents, *fp_contents_update;
@@ -81,7 +81,7 @@ qcheck_process_contents(q_vdb_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state)
 	fp_contents_update = NULL;
 
 	/* Open contents */
-	fd_contents = q_vdb_pkg_openat(pkg_ctx, "CONTENTS", O_RDONLY|O_CLOEXEC, 0);
+	fd_contents = vdb_pkg_openat(pkg_ctx, "CONTENTS", O_RDONLY|O_CLOEXEC, 0);
 	if (fd_contents == -1)
 		return EXIT_SUCCESS;
 	if (fstat(fd_contents, &cst)) {
@@ -99,7 +99,7 @@ qcheck_process_contents(q_vdb_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state)
 		(state->qc_update ? "Updat" : "Check"),
 		GREEN, catname, pkgname, NORM);
 	if (state->qc_update) {
-		fp_contents_update = q_vdb_pkg_fopenat_rw(pkg_ctx, "CONTENTS~");
+		fp_contents_update = vdb_pkg_fopenat_rw(pkg_ctx, "CONTENTS~");
 		if (fp_contents_update == NULL) {
 			fclose(fp_contents);
 			warnp("unable to fopen(%s/%s, w)", pkgname, "CONTENTS~");
@@ -363,7 +363,7 @@ qcheck_process_contents(q_vdb_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state)
 }
 
 static int
-qcheck_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
+qcheck_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct qcheck_opt_state *state = priv;
 	const char *catname = pkg_ctx->cat_ctx->name;
@@ -439,7 +439,7 @@ int qcheck_main(int argc, char **argv)
 			xarraypush_ptr(atoms, atom);
 	}
 
-	ret = q_vdb_foreach_pkg_sorted(portroot, portvdb, qcheck_cb, &state);
+	ret = vdb_foreach_pkg_sorted(portroot, portvdb, qcheck_cb, &state);
 	{
 		void *regex;
 		array_for_each(regex_arr, i, regex)

diff --git a/qdepends.c b/qdepends.c
index 7bb8818..e49e533 100644
--- a/qdepends.c
+++ b/qdepends.c
@@ -92,7 +92,7 @@ qdepends_print_depend(FILE *fp, const char *depend)
 }
 
 static int
-qdepends_results_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
+qdepends_results_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct qdepends_opt_state *state = priv;
 	depend_atom *atom;
@@ -116,7 +116,7 @@ qdepends_results_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 	 * *DEPEND alters the search somewhat and affects results printing.
 	 */
 
-	datom = q_vdb_get_atom(pkg_ctx);
+	datom = vdb_get_atom(pkg_ctx);
 	if (datom == NULL)
 		return ret;
 
@@ -145,7 +145,7 @@ qdepends_results_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 	for (i = QMODE_DEPEND; i <= QMODE_BDEPEND; i <<= 1, dfile++) {
 		if (!(state->qmode & i))
 			continue;
-		if (!q_vdb_pkg_eat(pkg_ctx, *dfile,
+		if (!vdb_pkg_eat(pkg_ctx, *dfile,
 					&state->depend, &state->depend_len))
 			continue;
 
@@ -302,7 +302,7 @@ int qdepends_main(int argc, char **argv)
 			xarraypush_ptr(atoms, atom);
 	}
 
-	ret = q_vdb_foreach_pkg(portroot, portvdb,
+	ret = vdb_foreach_pkg(portroot, portvdb,
 			qdepends_results_cb, &state, NULL);
 
 	if (state.depend != NULL)

diff --git a/qfile.c b/qfile.c
index 19b156e..3d1543e 100644
--- a/qfile.c
+++ b/qfile.c
@@ -74,7 +74,7 @@ struct qfile_opt_state {
  * We assume the people calling us have chdir(/var/db/pkg) and so
  * we use relative paths throughout here.
  */
-static int qfile_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
+static int qfile_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct qfile_opt_state *state = priv;
 	const char *catname = pkg_ctx->cat_ctx->name;
@@ -115,14 +115,14 @@ static int qfile_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 		}
 		if (state->exclude_slot == NULL)
 			goto qlist_done; /* "(CAT/)?(PN|PF)" matches, and no SLOT specified */
-		q_vdb_pkg_eat(pkg_ctx, "SLOT", &state->buf, &state->buflen);
+		vdb_pkg_eat(pkg_ctx, "SLOT", &state->buf, &state->buflen);
 		rmspace(state->buf);
 		if (strcmp(state->exclude_slot, state->buf) == 0)
 			goto qlist_done; /* "(CAT/)?(PN|PF):SLOT" matches */
 	}
  dont_skip_pkg: /* End of the package exclusion tests. */
 
-	fp = q_vdb_pkg_fopenat_ro(pkg_ctx, "CONTENTS");
+	fp = vdb_pkg_fopenat_ro(pkg_ctx, "CONTENTS");
 	if (fp == NULL)
 		goto qlist_done;
 
@@ -227,7 +227,7 @@ static int qfile_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 					/* XXX: This assumes the buf is big enough. */
 					char *slot_hack = slot + 1;
 					size_t slot_len = sizeof(slot) - 1;
-					q_vdb_pkg_eat(pkg_ctx, "SLOT", &slot_hack, &slot_len);
+					vdb_pkg_eat(pkg_ctx, "SLOT", &slot_hack, &slot_len);
 					rmspace(slot_hack);
 					slot[0] = ':';
 				} else
@@ -479,7 +479,7 @@ int qfile_main(int argc, char **argv)
 	nb_of_queries = prepare_qfile_args(argc, (const char **) argv, &state);
 	/* Now do the actual `qfile` checking */
 	if (nb_of_queries > 0)
-		found += q_vdb_foreach_pkg_sorted(portroot, portvdb, qfile_cb, &state);
+		found += vdb_foreach_pkg_sorted(portroot, portvdb, qfile_cb, &state);
 
 	if (state.args.non_orphans) {
 		/* display orphan files */

diff --git a/qgrep.c b/qgrep.c
index 6cb5697..f38f461 100644
--- a/qgrep.c
+++ b/qgrep.c
@@ -441,7 +441,7 @@ qgrep_cache_cb(cache_pkg_ctx *pkg_ctx, void *priv)
 }
 
 static int
-qgrep_vdb_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
+qgrep_vdb_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct qgrep_grepargs *data = (struct qgrep_grepargs *)priv;
 	char buf[_Q_PATH_MAX];
@@ -687,7 +687,7 @@ int qgrep_main(int argc, char **argv)
 			}
 			closedir(eclass_dir);
 		} else if (do_installed) {
-			status = q_vdb_foreach_pkg(portroot, portvdb,
+			status = vdb_foreach_pkg(portroot, portvdb,
 					qgrep_vdb_cb, &args, NULL);
 		} else { /* do_ebuild */
 			status = cache_foreach_pkg(portroot, overlay,

diff --git a/qlist.c b/qlist.c
index 313ff56..9314385 100644
--- a/qlist.c
+++ b/qlist.c
@@ -96,7 +96,7 @@ cmpstringp(const void *p1, const void *p2)
  */
 static char _umapstr_buf[BUFSIZ];
 static const char *
-umapstr(char display, q_vdb_pkg_ctx *pkg_ctx)
+umapstr(char display, vdb_pkg_ctx *pkg_ctx)
 {
 	char *bufp = _umapstr_buf;
 	char *use = NULL;
@@ -115,10 +115,10 @@ umapstr(char display, q_vdb_pkg_ctx *pkg_ctx)
 	if (!display)
 		return bufp;
 
-	q_vdb_pkg_eat(pkg_ctx, "USE", &use, &use_len);
+	vdb_pkg_eat(pkg_ctx, "USE", &use, &use_len);
 	if (!use[0])
 		return bufp;
-	q_vdb_pkg_eat(pkg_ctx, "IUSE", &iuse, &iuse_len);
+	vdb_pkg_eat(pkg_ctx, "IUSE", &iuse, &iuse_len);
 	if (!iuse[0])
 		return bufp;
 
@@ -173,13 +173,13 @@ umapstr(char display, q_vdb_pkg_ctx *pkg_ctx)
 /* forward declaration necessary for misuse from qmerge.c, see HACK there */
 bool
 qlist_match(
-		q_vdb_pkg_ctx *pkg_ctx,
+		vdb_pkg_ctx *pkg_ctx,
 		const char *name,
 		depend_atom **name_atom,
 		bool exact);
 bool
 qlist_match(
-		q_vdb_pkg_ctx *pkg_ctx,
+		vdb_pkg_ctx *pkg_ctx,
 		const char *name,
 		depend_atom **name_atom,
 		bool exact)
@@ -200,7 +200,7 @@ qlist_match(
 			uslot = NULL;
 		else {
 			if (!pkg_ctx->slot)
-				q_vdb_pkg_eat(pkg_ctx, "SLOT", &pkg_ctx->slot,
+				vdb_pkg_eat(pkg_ctx, "SLOT", &pkg_ctx->slot,
 						&pkg_ctx->slot_len);
 			uslot_len = strlen(uslot);
 		}
@@ -209,7 +209,7 @@ qlist_match(
 	urepo = strstr(name, "::");
 	if (urepo) {
 		if (!pkg_ctx->repo)
-			q_vdb_pkg_eat(pkg_ctx, "repository", &pkg_ctx->repo,
+			vdb_pkg_eat(pkg_ctx, "repository", &pkg_ctx->repo,
 					&pkg_ctx->repo_len);
 		urepo += 2;
 		urepo_len = strlen(urepo);
@@ -338,7 +338,7 @@ struct qlist_opt_state {
 };
 
 static int
-qlist_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
+qlist_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct qlist_opt_state *state = priv;
 	int i;
@@ -359,7 +359,7 @@ qlist_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 		atom = (verbose ? NULL : atom_explode(pkgname));
 		if ((state->all + state->just_pkgname) < 2) {
 			if (state->show_slots && !pkg_ctx->slot) {
-				q_vdb_pkg_eat(pkg_ctx, "SLOT",
+				vdb_pkg_eat(pkg_ctx, "SLOT",
 						&pkg_ctx->slot, &pkg_ctx->slot_len);
 				/* chop off the subslot if desired */
 				if (state->show_slots == 1) {
@@ -369,7 +369,7 @@ qlist_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 				}
 			}
 			if (state->show_repo && !pkg_ctx->repo)
-				q_vdb_pkg_eat(pkg_ctx, "repository",
+				vdb_pkg_eat(pkg_ctx, "repository",
 						&pkg_ctx->repo, &pkg_ctx->repo_len);
 			/* display it */
 			printf("%s%s/%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
@@ -398,7 +398,7 @@ qlist_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 		printf("%s%s/%s%s%s %sCONTENTS%s:\n",
 				BOLD, catname, BLUE, pkgname, NORM, DKBLUE, NORM);
 
-	fp = q_vdb_pkg_fopenat_ro(pkg_ctx, "CONTENTS");
+	fp = vdb_pkg_fopenat_ro(pkg_ctx, "CONTENTS");
 	if (fp == NULL)
 		return 1;
 
@@ -489,7 +489,7 @@ int qlist_main(int argc, char **argv)
 
 	state.buf = xmalloc(state.buflen);
 	state.atoms = xcalloc(argc - optind, sizeof(*state.atoms));
-	ret = q_vdb_foreach_pkg_sorted(portroot, portvdb, qlist_cb, &state);
+	ret = vdb_foreach_pkg_sorted(portroot, portvdb, qlist_cb, &state);
 	free(state.buf);
 	for (i = optind; i < state.argc; ++i)
 		if (state.atoms[i - optind])

diff --git a/qmerge.c b/qmerge.c
index 97726db..41488fa 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -118,7 +118,7 @@ typedef struct llist_char_t llist_char;
 
 static void pkg_fetch(int, const depend_atom *, const struct pkg_t *);
 static void pkg_merge(int, const depend_atom *, const struct pkg_t *);
-static int pkg_unmerge(q_vdb_pkg_ctx *, set *, int, char **, int, char **);
+static int pkg_unmerge(vdb_pkg_ctx *, set *, int, char **, int, char **);
 static struct pkg_t *grab_binpkg_info(const char *);
 static char *find_binpkg(const char *);
 
@@ -282,7 +282,7 @@ struct qmerge_bv_state {
 };
 
 static int
-qmerge_filter_cat(q_vdb_cat_ctx *cat_ctx, void *priv)
+qmerge_filter_cat(vdb_cat_ctx *cat_ctx, void *priv)
 {
 	struct qmerge_bv_state *state = priv;
 	return !state->catname || strcmp(cat_ctx->name, state->catname) == 0;
@@ -292,13 +292,13 @@ qmerge_filter_cat(q_vdb_cat_ctx *cat_ctx, void *priv)
  * should however figure out how to do what match does here from e.g.
  * atom */
 extern bool qlist_match(
-		q_vdb_pkg_ctx *pkg_ctx,
+		vdb_pkg_ctx *pkg_ctx,
 		const char *name,
 		depend_atom **name_atom,
 		bool exact);
 
 static int
-qmerge_best_version_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
+qmerge_best_version_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct qmerge_bv_state *state = priv;
 	if (qlist_match(pkg_ctx, state->buf, NULL, true))
@@ -338,7 +338,7 @@ best_version(const char *catname, const char *pkgname, const char *slot)
 	retbuf[0] = '\0';
 	snprintf(state.buf, sizeof(state.buf), "%s%s%s:%s",
 		 catname ? : "", catname ? "/" : "", pkgname, slot);
-	q_vdb_foreach_pkg(portroot, portvdb,
+	vdb_foreach_pkg(portroot, portvdb,
 			qmerge_best_version_cb, &state, qmerge_filter_cat);
 
  done:
@@ -999,8 +999,8 @@ static void
 pkg_merge(int level, const depend_atom *atom, const struct pkg_t *pkg)
 {
 	set *objs;
-	q_vdb_ctx *vdb_ctx;
-	q_vdb_cat_ctx *cat_ctx;
+	vdb_ctx *vdb;
+	vdb_cat_ctx *cat_ctx;
 	FILE *fp, *contents;
 	static char *phases;
 	static size_t phases_len;
@@ -1122,19 +1122,19 @@ pkg_merge(int level, const depend_atom *atom, const struct pkg_t *pkg)
 	}
 
 	/* Get a handle on the main vdb repo */
-	vdb_ctx = q_vdb_open(portroot, portvdb);
-	if (!vdb_ctx)
+	vdb = vdb_open(portroot, portvdb);
+	if (!vdb)
 		return;
-	cat_ctx = q_vdb_open_cat(vdb_ctx, pkg->CATEGORY);
+	cat_ctx = vdb_open_cat(vdb, pkg->CATEGORY);
 	if (!cat_ctx) {
 		if (errno != ENOENT) {
-			q_vdb_close(vdb_ctx);
+			vdb_close(vdb);
 			return;
 		}
-		mkdirat(vdb_ctx->vdb_fd, pkg->CATEGORY, 0755);
-		cat_ctx = q_vdb_open_cat(vdb_ctx, pkg->CATEGORY);
+		mkdirat(vdb->vdb_fd, pkg->CATEGORY, 0755);
+		cat_ctx = vdb_open_cat(vdb, pkg->CATEGORY);
 		if (!cat_ctx) {
-			q_vdb_close(vdb_ctx);
+			vdb_close(vdb);
 			return;
 		}
 	}
@@ -1345,10 +1345,10 @@ pkg_merge(int level, const depend_atom *atom, const struct pkg_t *pkg)
 	/* TODO: Should see about merging with unmerge_packages() */
 	while (1) {
 		int ret;
-		q_vdb_pkg_ctx *pkg_ctx;
+		vdb_pkg_ctx *pkg_ctx;
 		depend_atom *old_atom;
 
-		pkg_ctx = q_vdb_next_pkg(cat_ctx);
+		pkg_ctx = vdb_next_pkg(cat_ctx);
 		if (!pkg_ctx)
 			break;
 
@@ -1377,7 +1377,7 @@ pkg_merge(int level, const depend_atom *atom, const struct pkg_t *pkg)
 
 		pkg_unmerge(pkg_ctx, objs, cp_argc, cp_argv, cpm_argc, cpm_argv);
  next_pkg:
-		q_vdb_close_pkg(pkg_ctx);
+		vdb_close_pkg(pkg_ctx);
 	}
 
 	freeargv(cp_argc, cp_argv);
@@ -1416,14 +1416,14 @@ pkg_merge(int level, const depend_atom *atom, const struct pkg_t *pkg)
 	printf("%s>>>%s %s%s%s/%s%s%s\n",
 			YELLOW, NORM, WHITE, atom->CATEGORY, NORM, CYAN, atom->PN, NORM);
 
-	q_vdb_close(vdb_ctx);
+	vdb_close(vdb);
 }
 
 static int
-pkg_unmerge(q_vdb_pkg_ctx *pkg_ctx, set *keep,
+pkg_unmerge(vdb_pkg_ctx *pkg_ctx, set *keep,
 		int cp_argc, char **cp_argv, int cpm_argc, char **cpm_argv)
 {
-	q_vdb_cat_ctx *cat_ctx = pkg_ctx->cat_ctx;
+	vdb_cat_ctx *cat_ctx = pkg_ctx->cat_ctx;
 	const char *cat = cat_ctx->name;
 	const char *pkgname = pkg_ctx->name;
 	size_t buflen;
@@ -1447,7 +1447,7 @@ pkg_unmerge(q_vdb_pkg_ctx *pkg_ctx, set *keep,
 		return 0;
 
 	/* First get a handle on the things to clean up */
-	fp = q_vdb_pkg_fopenat_ro(pkg_ctx, "CONTENTS");
+	fp = vdb_pkg_fopenat_ro(pkg_ctx, "CONTENTS");
 	if (fp == NULL)
 		return ret;
 
@@ -1455,7 +1455,7 @@ pkg_unmerge(q_vdb_pkg_ctx *pkg_ctx, set *keep,
 
 	/* Then execute the pkg_prerm step */
 	if (!pretend) {
-		q_vdb_pkg_eat(pkg_ctx, "DEFINED_PHASES", &phases, &phases_len);
+		vdb_pkg_eat(pkg_ctx, "DEFINED_PHASES", &phases, &phases_len);
 		mkdirat(pkg_ctx->fd, "temp", 0755);
 		pkg_run_func_at(pkg_ctx->fd, ".", phases, "pkg_prerm", T, T);
 	}
@@ -1776,7 +1776,7 @@ print_Pkg(int full, const depend_atom *atom, const struct pkg_t *pkg)
 }
 
 static int
-qmerge_unmerge_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
+qmerge_unmerge_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 {
 	int cp_argc;
 	int cpm_argc;
@@ -1804,7 +1804,7 @@ qmerge_unmerge_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 static int
 unmerge_packages(set *todo)
 {
-	return q_vdb_foreach_pkg(portroot, portvdb, qmerge_unmerge_cb, todo, NULL);
+	return vdb_foreach_pkg(portroot, portvdb, qmerge_unmerge_cb, todo, NULL);
 }
 
 static FILE *

diff --git a/qpkg.c b/qpkg.c
index af8df37..b93823b 100644
--- a/qpkg.c
+++ b/qpkg.c
@@ -334,9 +334,9 @@ qpkg_make(depend_atom *atom)
 
 int qpkg_main(int argc, char **argv)
 {
-	q_vdb_ctx *ctx;
-	q_vdb_cat_ctx *cat_ctx;
-	q_vdb_pkg_ctx *pkg_ctx;
+	vdb_ctx *ctx;
+	vdb_cat_ctx *cat_ctx;
+	vdb_pkg_ctx *pkg_ctx;
 	size_t s, pkgs_made;
 	int i;
 	struct stat st;
@@ -417,15 +417,15 @@ retry_mkdir:
 	}
 
 	/* now try to run through vdb and locate matches for user inputs */
-	ctx = q_vdb_open(portroot, portvdb);
+	ctx = vdb_open(portroot, portvdb);
 	if (!ctx)
 		return EXIT_FAILURE;
 
 	/* scan all the categories */
-	while ((cat_ctx = q_vdb_next_cat(ctx))) {
+	while ((cat_ctx = vdb_next_cat(ctx))) {
 		/* scan all the packages in this category */
 		const char *catname = cat_ctx->name;
-		while ((pkg_ctx = q_vdb_next_pkg(cat_ctx))) {
+		while ((pkg_ctx = vdb_next_pkg(cat_ctx))) {
 			const char *pkgname = pkg_ctx->name;
 
 			/* see if user wants any of these packages */
@@ -449,7 +449,7 @@ retry_mkdir:
 			atom_implode(atom);
 
  next_pkg:
-			q_vdb_close_pkg(pkg_ctx);
+			vdb_close_pkg(pkg_ctx);
 		}
 	}
 

diff --git a/qsize.c b/qsize.c
index 80d496c..4fbbe47 100644
--- a/qsize.c
+++ b/qsize.c
@@ -97,7 +97,7 @@ struct qsize_opt_state {
 };
 
 static int
-qsize_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
+qsize_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct qsize_opt_state *state = priv;
 	const char *catname = pkg_ctx->cat_ctx->name;
@@ -126,7 +126,7 @@ qsize_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 	if (!showit)
 		return EXIT_SUCCESS;
 
-	if ((fp = q_vdb_pkg_fopenat_ro(pkg_ctx, "CONTENTS")) == NULL)
+	if ((fp = vdb_pkg_fopenat_ro(pkg_ctx, "CONTENTS")) == NULL)
 		return EXIT_SUCCESS;
 
 	num_ignored = num_files = num_nonfiles = num_bytes = 0;
@@ -230,7 +230,7 @@ int qsize_main(int argc, char **argv)
 	state.buflen = _Q_PATH_MAX;
 	state.buf = xmalloc(state.buflen);
 
-	ret = q_vdb_foreach_pkg(portroot, portvdb, qsize_cb, &state, NULL);
+	ret = vdb_foreach_pkg(portroot, portvdb, qsize_cb, &state, NULL);
 
 	if (state.summary) {
 		printf(" %sTotals%s: %'zu files, %'zu non-files, ", BOLD, NORM,


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2019-05-07  6:19 Fabian Groffen
  0 siblings, 0 replies; 23+ messages in thread
From: Fabian Groffen @ 2019-05-07  6:19 UTC (permalink / raw
  To: gentoo-commits

commit:     d26a4c6fab322e4310fad304258300e548384115
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon May  6 18:12:44 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon May  6 18:12:44 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=d26a4c6f

libq/atom: use less emphasis on PVR

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 TODO.md     |  4 ++--
 libq/atom.c | 10 +++++-----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/TODO.md b/TODO.md
index 6fda56d..3333fd6 100644
--- a/TODO.md
+++ b/TODO.md
@@ -8,9 +8,9 @@
 
 - disable color when tty = NULL; may break less?
 
-- standardize/unify/clean up misc handling of colors
+- standardize/unify/clean up misc handling of colors (atom\_format)
   define rules:
-    BOLD CATEGORY/ BLUE PKG BKBLUE -VER YELLOW :SLOT GREEN ::REPO NORM [ MAGENTA USE NORM ]
+    BOLD CATEGORY/ BLUE PKG CYAN -VER YELLOW :SLOT GREEN ::REPO NORM [ MAGENTA USE NORM ]
 
 - remove odd rmspace for each string in libq/set.c (allows a lot less
   malloc/frees)

diff --git a/libq/atom.c b/libq/atom.c
index 4df76a6..0eaee5c 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -676,23 +676,23 @@ atom_format_r(
 				} else if (!strncmp("PV", fmt, len)) {
 					if (showit || atom->PV)
 						append_buf(buf, buflen, "%s%s%s",
-								DKBLUE, HN(atom->PV), NORM);
+								CYAN, HN(atom->PV), NORM);
 				} else if (!strncmp("PVR", fmt, len)) {
 					if (showit || atom->PVR)
 						append_buf(buf, buflen, "%s%s%s",
-								DKBLUE, HN(atom->PVR), NORM);
+								CYAN, HN(atom->PVR), NORM);
 				} else if (!strncmp("PF", fmt, len)) {
 					append_buf(buf, buflen, "%s%s%s", BLUE, atom->PN, NORM);
 					if (atom->PV)
 						append_buf(buf, buflen, "%s-%s%s",
-								DKBLUE, atom->PV, NORM);
+								CYAN, atom->PV, NORM);
 					if (atom->PR_int)
 						append_buf(buf, buflen,"%s-r%d%s",
-								DKBLUE, atom->PR_int, NORM);
+								CYAN, atom->PR_int, NORM);
 				} else if (!strncmp("PR", fmt, len)) {
 					if (showit || atom->PR_int)
 						append_buf(buf, buflen, "%sr%d%s",
-								DKBLUE, atom->PR_int, NORM);
+								CYAN, atom->PR_int, NORM);
 				} else if (!strncmp("SLOT", fmt, len)) {
 					if (showit || atom->SLOT)
 						append_buf(buf, buflen, "%s%s%s%s%s%s%s",


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2019-07-14 13:09 Fabian Groffen
  0 siblings, 0 replies; 23+ messages in thread
From: Fabian Groffen @ 2019-07-14 13:09 UTC (permalink / raw
  To: gentoo-commits

commit:     2e4b280488b5f030a6e735060bb73667d1533fab
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Jul 14 12:10:08 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Jul 14 12:10:08 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=2e4b2804

libq/hash: ensure hash_compute_file operates on hashes requested

thinko probably due to extraction from hashgen at some point, pass
hashes with the function call, so it operates on the hashes the caller
wants it to.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/hash.c | 5 ++---
 libq/hash.h | 2 +-
 qmanifest.c | 4 ++--
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/libq/hash.c b/libq/hash.c
index 32d047a..6d0a62b 100644
--- a/libq/hash.c
+++ b/libq/hash.c
@@ -22,8 +22,6 @@
 
 #include "hash.h"
 
-static int hashes = HASH_DEFAULT;
-
 void
 hash_hex(char *out, const unsigned char *buf, const int length)
 {
@@ -97,7 +95,8 @@ hash_compute_file(
 		char *sha512,
 		char *whrlpl,
 		char *blak2b,
-		size_t *flen)
+		size_t *flen,
+		int hashes)
 {
 	FILE *f;
 	char data[8192];

diff --git a/libq/hash.h b/libq/hash.h
index 157c454..89f3841 100644
--- a/libq/hash.h
+++ b/libq/hash.h
@@ -21,6 +21,6 @@ enum hash_impls {
 
 void hash_hex(char *out, const unsigned char *buf, const int length);
 void hash_compute_file(const char *fname, char *sha256, char *sha512,
-		char *whrlpl, char *blak2b, size_t *flen);
+		char *whrlpl, char *blak2b, size_t *flen, int hashes);
 
 #endif

diff --git a/qmanifest.c b/qmanifest.c
index 21254c3..41faa4c 100644
--- a/qmanifest.c
+++ b/qmanifest.c
@@ -201,7 +201,7 @@ write_hashes(
 
 	update_times(tv, &s);
 
-	hash_compute_file(fname, sha256, sha512, whrlpl, blak2b, &flen);
+	hash_compute_file(fname, sha256, sha512, whrlpl, blak2b, &flen, hashes);
 
 	len = snprintf(data, sizeof(data), "%s %s %zd", type, name, flen);
 	if (hashes & HASH_BLAKE2B)
@@ -1027,7 +1027,7 @@ verify_file(const char *dir, char *mfline, const char *mfest, verify_msg **msgs)
 
 	sha256[0] = sha512[0] = whrlpl[0] = blak2b[0] = '\0';
 	snprintf(buf, sizeof(buf), "%s/%s", dir, path);
-	hash_compute_file(buf, sha256, sha512, whrlpl, blak2b, &flen);
+	hash_compute_file(buf, sha256, sha512, whrlpl, blak2b, &flen, hashes);
 
 	if (flen == 0) {
 		msgs_add(msgs, mfest, path, "cannot open file!");


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2019-11-15 13:52 Fabian Groffen
  0 siblings, 0 replies; 23+ messages in thread
From: Fabian Groffen @ 2019-11-15 13:52 UTC (permalink / raw
  To: gentoo-commits

commit:     5ec1f4368412c8d6f02148d3d9cb109050c8c626
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri Nov 15 13:50:10 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Nov 15 13:50:10 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=5ec1f436

libq/xpak: rework to reuse more code

- introduce xpak_process{,_fd} to replace the very similar list and extract
- add _fd variant to be able to pass already open filedescriptor
- rework interface to carry a context pointer for the callback func for
  more flexibility
- adapt qxpak for the interface changes

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/xpak.c | 132 ++++++++++++++++++++++++++----------------------------------
 libq/xpak.h |  26 +++---------
 qxpak.c     |  98 ++++++++++++++++++++++++++------------------
 3 files changed, 120 insertions(+), 136 deletions(-)

diff --git a/libq/xpak.c b/libq/xpak.c
index c2e93f9..9692eab 100644
--- a/libq/xpak.c
+++ b/libq/xpak.c
@@ -39,23 +39,22 @@
 #define XPAK_END_MSG_LEN     8
 
 typedef struct {
-	int dir_fd;
+	void *ctx;
 	FILE *fp;
-	int index_len;
-	int data_len;
+	unsigned int index_len;
+	unsigned int data_len;
 	char *index, *data;
 } _xpak_archive;
 
-typedef void (*xpak_callback_t)(int,char*,int,int,int,char*);
-
 static void _xpak_walk_index(
 		_xpak_archive *x,
-		int argc,
-		char **argv,
 		xpak_callback_t func)
 {
-	int i, pathname_len, data_offset, data_len;
-	char *p, pathname[100];
+	unsigned int pathname_len;
+	unsigned int data_offset;
+	unsigned int data_len;
+	char *p;
+	char pathname[100];
 
 	p = x->index;
 	while ((p - x->index) < x->index_len) {
@@ -73,43 +72,26 @@ static void _xpak_walk_index(
 		p += 4;
 		data_len = READ_BE_INT32((unsigned char*)p);
 		p += 4;
-		if (argc) {
-			for (i = 0; i < argc; ++i) {
-				if (argv[i] && !strcmp(pathname, argv[i])) {
-					argv[i] = NULL;
-					break;
-				}
-			}
-			if (i == argc)
-				continue;
-		}
-		(*func)(x->dir_fd, pathname, pathname_len,
+		(*func)(x->ctx, pathname, pathname_len,
 				data_offset, data_len, x->data);
 	}
-
-	if (argc)
-		for (i = 0; i < argc; ++i)
-			if (argv[i])
-				warn("Could not locate '%s' in archive", argv[i]);
 }
 
-static _xpak_archive *_xpak_open(const char *file)
+static _xpak_archive *_xpak_open(const int fd)
 {
 	static _xpak_archive ret;
 	char buf[XPAK_START_LEN];
 
 	/* init the file */
 	memset(&ret, 0x00, sizeof(ret));
-	if (file[0] == '-' && file[1] == '\0')
-		ret.fp = stdin;
-	else if ((ret.fp = fopen(file, "r")) == NULL)
+	if ((ret.fp = fdopen(fd, "r")) == NULL)
 		return NULL;
 
 	/* verify this xpak doesnt suck */
 	if (fread(buf, 1, XPAK_START_LEN, ret.fp) != XPAK_START_LEN)
 		goto close_and_ret;
 	if (memcmp(buf, XPAK_START_MSG, XPAK_START_MSG_LEN)) {
-		warn("%s: Invalid xpak", file);
+		warn("Not an xpak file");
 		goto close_and_ret;
 	}
 
@@ -117,7 +99,7 @@ static _xpak_archive *_xpak_open(const char *file)
 	ret.index_len = READ_BE_INT32((unsigned char*)buf+XPAK_START_MSG_LEN);
 	ret.data_len = READ_BE_INT32((unsigned char*)buf+XPAK_START_MSG_LEN+4);
 	if (!ret.index_len || !ret.data_len) {
-		warn("Skipping empty archive '%s'", file);
+		warn("Skipping empty archive");
 		goto close_and_ret;
 	}
 
@@ -135,52 +117,21 @@ static void _xpak_close(_xpak_archive *x)
 }
 
 int
-xpak_list(
-		int dir_fd,
-		const char *file,
-		int argc,
-		char **argv,
-		xpak_callback_t func)
-{
-	_xpak_archive *x;
-	char buf[BUFSIZE];
-	size_t ret;
-
-	x = _xpak_open(file);
-	if (!x)
-		return 1;
-
-	x->dir_fd = dir_fd;
-	x->index = buf;
-	if (x->index_len >= sizeof(buf))
-		err("index length %d exceeds limit %zd", x->index_len, sizeof(buf));
-	ret = fread(x->index, 1, x->index_len, x->fp);
-	if (ret != (size_t)x->index_len)
-		err("insufficient data read, got %zd, requested %d", ret, x->index_len);
-	_xpak_walk_index(x, argc, argv, func);
-
-	_xpak_close(x);
-
-	return 0;
-}
-
-int
-xpak_extract(
-	int dir_fd,
-	const char *file,
-	int argc,
-	char **argv,
+xpak_process_fd(
+	int fd,
+	bool get_data,
+	void *ctx,
 	xpak_callback_t func)
 {
 	_xpak_archive *x;
 	char buf[BUFSIZE], ext[BUFSIZE*32];
 	size_t in;
 
-	x = _xpak_open(file);
+	x = _xpak_open(fd);
 	if (!x)
 		return 1;
 
-	x->dir_fd = dir_fd;
+	x->ctx = ctx;
 	x->index = buf;
 
 	if (x->index_len >= sizeof(buf))
@@ -189,22 +140,51 @@ xpak_extract(
 	if (in != (size_t)x->index_len)
 		err("insufficient data read, got %zd, requested %d", in, x->index_len);
 
-	/* the xpak may be large (like when it has CONTENTS) #300744 */
-	x->data = (size_t)x->data_len < sizeof(ext) ? ext : xmalloc(x->data_len);
-	in = fread(x->data, 1, x->data_len, x->fp);
-	if (in != (size_t)x->data_len)
-		err("insufficient data read, got %zd, requested %d", in, x->data_len);
+	if (get_data) {
+		/* the xpak may be large (like when it has CONTENTS) #300744 */
+		x->data = (size_t)x->data_len < sizeof(ext) ?
+			ext : xmalloc(x->data_len);
+		in = fread(x->data, 1, x->data_len, x->fp);
+		if (in != (size_t)x->data_len)
+			err("insufficient data read, got %zd, requested %d",
+					in, x->data_len);
+	} else {
+		x->data = NULL;
+		x->data_len = 0;
+	}
 
-	_xpak_walk_index(x, argc, argv, func);
+	_xpak_walk_index(x, func);
 
 	_xpak_close(x);
 
-	if (x->data != ext)
+	if (get_data && x->data != ext)
 		free(x->data);
 
 	return 0;
 }
 
+int
+xpak_process(
+	const char *file,
+	bool get_data,
+	void *ctx,
+	xpak_callback_t func)
+{
+	int fd = -1;
+	int ret;
+
+	if (file[0] == '-' && file[1] == '\0')
+		fd = 0;
+	else if ((fd = open(file, O_RDONLY | O_CLOEXEC)) == -1)
+		return -1;
+
+	ret = xpak_process_fd(fd, get_data, ctx, func);
+	if (ret != 0)
+		warn("Unable to open file '%s'", file);
+
+	return ret;
+}
+
 static void
 _xpak_add_file(
 		int dir_fd,
@@ -279,7 +259,7 @@ xpak_create(
 		const char *file,
 		int argc,
 		char **argv,
-		char append,
+		bool append,
 		int verbose)
 {
 	FILE *findex, *fdata, *fout;

diff --git a/libq/xpak.h b/libq/xpak.h
index 0b318b2..aeafdae 100644
--- a/libq/xpak.h
+++ b/libq/xpak.h
@@ -6,26 +6,12 @@
 #ifndef _XPAK_H
 #define _XPAK_H 1
 
-typedef void (*xpak_callback_t)(int,char*,int,int,int,char*);
+typedef void (*xpak_callback_t)(void *, char *, int, int, int, char *);
 
-int xpak_list(
-		int dir_fd,
-		const char *file,
-		int argc,
-		char **argv,
-		xpak_callback_t func);
-int xpak_extract(
-	int dir_fd,
-	const char *file,
-	int argc,
-	char **argv,
-	xpak_callback_t func);
-int xpak_create(
-		int dir_fd,
-		const char *file,
-		int argc,
-		char **argv,
-		char append,
-		int v);
+int xpak_process_fd(int, bool, void *, xpak_callback_t);
+int xpak_process(const char *, bool, void *, xpak_callback_t);
+#define xpak_list(A,B,C)    xpak_process(A,false,B,C)
+#define xpak_extract(A,B,C) xpak_process(A,true,B,C)
+int xpak_create(int, const char *, int, char **, bool, int);
 
 #endif

diff --git a/qxpak.c b/qxpak.c
index eb19cae..fd0ec5d 100644
--- a/qxpak.c
+++ b/qxpak.c
@@ -42,31 +42,16 @@ static const char * const qxpak_opts_help[] = {
 
 static char xpak_stdout;
 
-static void
-_xpak_list_callback(
-		int dir_fd,
-		char *pathname,
-		int pathname_len,
-		int data_offset,
-		int data_len,
-		char *data)
-{
-	(void)dir_fd;
-	(void)pathname_len;
-	(void)data;
-
-	if (!verbose)
-		puts(pathname);
-	else if (verbose == 1)
-		printf("%s: %i byte%c\n", pathname, data_len, (data_len>1?'s':' '));
-	else
-		printf("%s: %i byte%c @ offset byte %i\n",
-			pathname, data_len, (data_len>1?'s':' '), data_offset);
-}
+struct qxpak_cb {
+	int dir_fd;
+	int argc;
+	char **argv;
+	bool extract;
+};
 
 static void
-_xpak_extract_callback(
-	int dir_fd,
+_xpak_callback(
+	void *ctx,
 	char *pathname,
 	int pathname_len,
 	int data_offset,
@@ -74,16 +59,38 @@ _xpak_extract_callback(
 	char *data)
 {
 	FILE *out;
-	(void)pathname_len;
+	struct qxpak_cb *xctx = (struct qxpak_cb *)ctx;
+
+	/* see if there is a match when there is a selection */
+	if (xctx->argc > 0) {
+		int i;
+		for (i = 0; i < xctx->argc; i++) {
+			if (xctx->argv[i] && !strcmp(pathname, xctx->argv[i])) {
+				xctx->argv[i] = NULL;
+				break;
+			}
+		}
+		if (i == xctx->argc)
+			return;
+	}
 
-	if (verbose == 1)
-		puts(pathname);
-	else if (verbose > 1)
-		printf("%s: %i byte%c\n", pathname, data_len, (data_len>1?'s':' '));
+	if (verbose == 0 + (xctx->extract ? 1 : 0))
+		printf("%.*s", pathname_len, pathname);
+	else if (verbose == 1 + (xctx->extract ? 1 : 0))
+		printf("%.*s: %d byte%s\n",
+				pathname_len, pathname,
+				data_len, (data_len > 1 ? "s" : ""));
+	else
+		printf("%.*s: %d byte%s @ offset byte %d\n",
+				pathname_len, pathname,
+				data_len, (data_len > 1 ? "s" : ""), data_offset);
+
+	if (!xctx->extract)
+		return;
 
 	if (!xpak_stdout) {
-		int fd = openat(dir_fd, pathname,
-				O_WRONLY|O_CLOEXEC|O_CREAT|O_TRUNC, 0644);
+		int fd = openat(xctx->dir_fd, pathname,
+				O_WRONLY | O_CLOEXEC | O_CREAT | O_TRUNC, 0644);
 		if (fd < 0)
 			return;
 		out = fdopen(fd, "w");
@@ -101,12 +108,14 @@ _xpak_extract_callback(
 int qxpak_main(int argc, char **argv)
 {
 	enum { XPAK_ACT_NONE, XPAK_ACT_LIST, XPAK_ACT_EXTRACT, XPAK_ACT_CREATE };
-	int i, ret, dir_fd;
+	int i, ret;
 	char *xpak;
 	char action = XPAK_ACT_NONE;
+	struct qxpak_cb cbctx;
 
-	dir_fd = AT_FDCWD;
 	xpak_stdout = 0;
+	cbctx.dir_fd = AT_FDCWD;
+	cbctx.extract = false;
 
 	while ((i = GETOPT_LONG(QXPAK, qxpak, "")) != -1) {
 		switch (i) {
@@ -116,10 +125,10 @@ int qxpak_main(int argc, char **argv)
 		case 'c': action = XPAK_ACT_CREATE; break;
 		case 'O': xpak_stdout = 1; break;
 		case 'd':
-			if (dir_fd != AT_FDCWD)
+			if (cbctx.dir_fd != AT_FDCWD)
 				err("Only use -d once");
-			dir_fd = open(optarg, O_RDONLY|O_CLOEXEC|O_PATH);
-			if (dir_fd < 0)
+			cbctx.dir_fd = open(optarg, O_RDONLY|O_CLOEXEC|O_PATH);
+			if (cbctx.dir_fd < 0)
 				errp("Could not open directory %s", optarg);
 			break;
 		}
@@ -130,23 +139,32 @@ int qxpak_main(int argc, char **argv)
 	xpak = argv[optind++];
 	argc -= optind;
 	argv += optind;
+	cbctx.argc = argc;
+	cbctx.argv = argv;
 
 	switch (action) {
 	case XPAK_ACT_LIST:
-		ret = xpak_list(dir_fd, xpak, argc, argv, &_xpak_list_callback);
+		ret = xpak_list(xpak, &cbctx, &_xpak_callback);
 		break;
 	case XPAK_ACT_EXTRACT:
-		ret = xpak_extract(dir_fd, xpak, argc, argv, &_xpak_extract_callback);
+		cbctx.extract = true;
+		ret = xpak_extract(xpak, &cbctx, &_xpak_callback);
 		break;
 	case XPAK_ACT_CREATE:
-		ret = xpak_create(dir_fd, xpak, argc, argv, 0, verbose);
+		ret = xpak_create(cbctx.dir_fd, xpak, argc, argv, 0, verbose);
 		break;
 	default:
 		ret = EXIT_FAILURE;
 	}
 
-	if (dir_fd != AT_FDCWD)
-		close(dir_fd);
+	if (cbctx.dir_fd != AT_FDCWD)
+		close(cbctx.dir_fd);
+
+	/* warn about non-matched args */
+	if (argc > 0 && (action == XPAK_ACT_LIST || action == XPAK_ACT_EXTRACT))
+		for (i = 0; i < argc; ++i)
+			if (argv[i])
+				warn("Could not locate '%s' in archive", argv[i]);
 
 	return ret;
 }


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2020-01-01 17:54 Fabian Groffen
  0 siblings, 0 replies; 23+ messages in thread
From: Fabian Groffen @ 2020-01-01 17:54 UTC (permalink / raw
  To: gentoo-commits

commit:     3e6a2e36af413a4dc1469a4042c8ce1aae95dfc9
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Wed Jan  1 17:53:32 2020 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Wed Jan  1 17:53:32 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=3e6a2e36

*: use new PF in places were it was simulated

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/atom.c |  5 +----
 libq/tree.c | 10 ++++------
 qgrep.c     |  7 +++----
 qlist.c     | 22 ++++++++++------------
 qlop.c      | 14 +++++---------
 qpkg.c      | 13 ++++---------
 6 files changed, 27 insertions(+), 44 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index 6f70847..946e821 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -794,10 +794,7 @@ atom_format_r(
 					append_buf(buf, buflen, "%s%s%s", BLUE, atom->PN, NORM);
 					if (atom->PV)
 						append_buf(buf, buflen, "%s-%s%s",
-								CYAN, atom->PV, NORM);
-					if (atom->PR_int)
-						append_buf(buf, buflen,"%s-r%d%s",
-								CYAN, atom->PR_int, NORM);
+								CYAN, atom->PVR, NORM);
 				} else if (!strncmp("PR", fmt, len)) {
 					if (showit || atom->PR_int)
 						append_buf(buf, buflen, "%sr%d%s",

diff --git a/libq/tree.c b/libq/tree.c
index bac9d00..377af83 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2020 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2008 Ned Ludd        - <solar@gentoo.org>
@@ -1196,8 +1196,8 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb callback, void *priv)
 						tree_close_cat(cat);
 					pkg->cat_ctx = cat = tree_open_cat(ctx, atom->CATEGORY);
 				}
-				pkgnamelen = snprintf(pkgname, sizeof(pkgname), "%s-%s.tbz2",
-						atom->PN, atom->PR_int > 0 ? atom->PVR : atom->PV);
+				pkgnamelen = snprintf(pkgname, sizeof(pkgname),
+						"%s.tbz2", atom->PF);
 				pkgname[pkgnamelen - (sizeof(".tbz2") - 1)] = '\0';
 				pkg->name = pkgname;
 				pkg->slot = meta->Q_SLOT == NULL ? (char *)"0" : meta->Q_SLOT;
@@ -1389,9 +1389,7 @@ static int tree_get_atoms_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 	char abuf[BUFSIZ];
 
 	if (state->fullcpv) {
-		snprintf(abuf, sizeof(abuf), "%s/%s-%s",
-				atom->CATEGORY, atom->PN,
-				atom->PR_int > 0 ? atom->PVR : atom->PV);
+		snprintf(abuf, sizeof(abuf), "%s/%s", atom->CATEGORY, atom->PF);
 		state->cpf = add_set(abuf, state->cpf);
 	} else {
 		snprintf(abuf, sizeof(abuf), "%s/%s", atom->CATEGORY, atom->PN);

diff --git a/qgrep.c b/qgrep.c
index 2a64d1b..4d8c27f 100644
--- a/qgrep.c
+++ b/qgrep.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2020 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005      Petteri Räty    - <betelgeuse@gentoo.org>
@@ -416,9 +416,8 @@ qgrep_cache_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 	}
 
 	/* cat/pkg/pkg-ver.ebuild */
-	snprintf(buf, sizeof(buf), "%s/%s/%s-%s.ebuild",
-			patom->CATEGORY, patom->PN, patom->PN,
-			patom->PR_int > 0 ? patom->PVR : patom->PV);
+	snprintf(buf, sizeof(buf), "%s/%s/%s.ebuild",
+			patom->CATEGORY, patom->PN, patom->PF);
 
 	label = NULL;
 	if (data->show_name) {

diff --git a/qlist.c b/qlist.c
index 1d4862f..f77eaea 100644
--- a/qlist.c
+++ b/qlist.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2020 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005 Martin Schlemmer     - <azarah@gentoo.org>
@@ -262,10 +262,9 @@ qlist_match(
 	if (exact) {
 		int i;
 
-		snprintf(buf, sizeof(buf), "%s/%s-%s%s%s%s%s%s%s",
+		snprintf(buf, sizeof(buf), "%s/%s%s%s%s%s%s%s",
 			atom->CATEGORY,
-			atom->PN,
-			atom->PVR,
+			atom->PF,
 			atom->SLOT != NULL ? ":" : "",
 			atom->SLOT != NULL ? atom->SLOT : "",
 			atom->SUBSLOT != NULL ? "/" : "",
@@ -273,10 +272,10 @@ qlist_match(
 			atom->REPO != NULL ? "::" : "",
 			atom->REPO != NULL ? atom->REPO : "");
 
-		/* exact match: CAT/PN-PVR[:SLOT][::REPO] */
+		/* exact match: CAT/PF[:SLOT][::REPO] */
 		if (strcmp(name, buf) == 0)
 			return true;
-		/* exact match: PN-PVR[:SLOT][::REPO] */
+		/* exact match: PF[:SLOT][::REPO] */
 		if (strcmp(name, strstr(buf, "/") + 1) == 0)
 			return true;
 
@@ -294,15 +293,14 @@ qlist_match(
 		if (strcmp(name, strstr(buf, "/") + 1) == 0)
 			return true;
 	} else {
-		/* partial leading match: CAT/PN-PVR */
-		snprintf(buf, sizeof(buf), "%s/%s-%s",
-				atom->CATEGORY, atom->PN, atom->PVR);
+		/* partial leading match: CAT/PF */
+		snprintf(buf, sizeof(buf), "%s/%s",
+				atom->CATEGORY, atom->PF);
 		if (strncmp(name, buf, pf_len) == 0 ||
 				rematch(name, buf, REG_EXTENDED) == 0)
 			return true;
-		/* partial leading match: PN-PVR */
-		snprintf(buf, sizeof(buf), "%s-%s", atom->PN, atom->PVR);
-		if (strncmp(name, buf, pf_len) == 0 ||
+		/* partial leading match: PF */
+		if (strncmp(name, atom->PF, pf_len) == 0 ||
 				rematch(name, buf, REG_EXTENDED) == 0)
 			return true;
 	}

diff --git a/qlop.c b/qlop.c
index 3120d85..9fa1387 100644
--- a/qlop.c
+++ b/qlop.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2020 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
@@ -654,10 +654,8 @@ static int do_emerge_log(
 							snprintf(afmt, sizeof(afmt), "%s/%s",
 								pkgw->atom->CATEGORY, pkgw->atom->PN);
 						} else {
-							snprintf(afmt, sizeof(afmt), "%s/%s-%s",
-								pkgw->atom->CATEGORY, pkgw->atom->PN,
-								pkgw->atom->PR_int > 0 ?
-								pkgw->atom->PVR : pkgw->atom->PV);
+							snprintf(afmt, sizeof(afmt), "%s/%s",
+								pkgw->atom->CATEGORY, pkgw->atom->PF);
 						}
 
 						pkg = add_set_value(afmt, pkgw, merge_averages);
@@ -798,10 +796,8 @@ static int do_emerge_log(
 							snprintf(afmt, sizeof(afmt), "%s/%s",
 								pkgw->atom->CATEGORY, pkgw->atom->PN);
 						} else {
-							snprintf(afmt, sizeof(afmt), "%s/%s-%s",
-								pkgw->atom->CATEGORY, pkgw->atom->PN,
-								pkgw->atom->PR_int > 0 ?
-								pkgw->atom->PVR : pkgw->atom->PV);
+							snprintf(afmt, sizeof(afmt), "%s/%s",
+								pkgw->atom->CATEGORY, pkgw->atom->PF);
 						}
 
 						pkg = add_set_value(afmt, pkgw, unmerge_averages);

diff --git a/qpkg.c b/qpkg.c
index f5e8168..9d2d82a 100644
--- a/qpkg.c
+++ b/qpkg.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2020 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd	       - <solar@gentoo.org>
@@ -54,11 +54,6 @@ extern char pretend;
 static char *qpkg_bindir = NULL;
 static int eclean = 0;
 
-static char *
-atom_to_pvr(depend_atom *atom) {
-	return (atom->PR_int == 0 ? atom->P : atom->PVR );
-}
-
 /* checks to make sure this is a .tbz2 file. used by scandir() */
 static int
 filter_tbz2(const struct dirent *dentry)
@@ -228,7 +223,7 @@ qpkg_make(depend_atom *atom)
 	buf = xmalloc(buflen);
 
 	snprintf(buf, buflen, "%s/%s/%s/CONTENTS",
-			portvdb, atom->CATEGORY, atom_to_pvr(atom));
+			portvdb, atom->CATEGORY, atom->PF);
 	if ((fp = fopen(buf, "r")) == NULL) {
 		free(buf);
 		return -1;
@@ -293,7 +288,7 @@ qpkg_make(depend_atom *atom)
 	xpaksize = st.st_size;
 
 	snprintf(buf, buflen, "%s/%s/%s",
-			portvdb, atom->CATEGORY, atom_to_pvr(atom));
+			portvdb, atom->CATEGORY, atom->PF);
 	xpak_argv[0] = buf;
 	xpak_argv[1] = NULL;
 	xpak_create(AT_FDCWD, tbz2, 1, xpak_argv, 1, verbose);
@@ -316,7 +311,7 @@ qpkg_make(depend_atom *atom)
 	mkdir_p(buf, 0755);
 
 	snprintf(buf, buflen, "%s/%s/%s.tbz2",
-			qpkg_bindir, atom->CATEGORY, atom_to_pvr(atom));
+			qpkg_bindir, atom->CATEGORY, atom->PF);
 	if (rename(tbz2, buf)) {
 		warnp("could not move '%s' to '%s'", tbz2, buf);
 		free(buf);


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2020-01-04 19:48 Fabian Groffen
  0 siblings, 0 replies; 23+ messages in thread
From: Fabian Groffen @ 2020-01-04 19:48 UTC (permalink / raw
  To: gentoo-commits

commit:     8b4086e7e32e3e548929fa532056a65188f8def8
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat Jan  4 19:47:57 2020 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Jan  4 19:47:57 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=8b4086e7

libq/tree: ignore Packages file when seemingly outdated

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 TODO.md     |  1 -
 libq/tree.c | 18 ++++++++++++++++--
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/TODO.md b/TODO.md
index 1de8b5f..ded7553 100644
--- a/TODO.md
+++ b/TODO.md
@@ -15,7 +15,6 @@
 - parse package.accept\_keywords such that we can provide the latest
   "available" version like Portage
 - check timestamps in libq/tree for choosing which method to take:
-	- ignore Packages when it is older than the last directory change
 	- ignore metadata when ebuild is modified
 	- add some method to skip these checks and assume everything is right
 

diff --git a/libq/tree.c b/libq/tree.c
index 49b2fa1..976f166 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -133,11 +133,25 @@ tree_open_binpkg(const char *sroot, const char *spkg)
 	char buf[_Q_PATH_MAX];
 
 	if (ret != NULL) {
+		struct stat st;
+		struct timespec pkgstim;
+
 		ret->cachetype = CACHE_BINPKGS;
 
 		snprintf(buf, sizeof(buf), "%s%s/%s", sroot, spkg, binpkg_packages);
-		if (eat_file(buf, &ret->pkgs, &ret->pkgslen))
-			ret->cachetype = CACHE_PACKAGES;
+		if (eat_file(buf, &ret->pkgs, &ret->pkgslen)) {
+			if (stat(buf, &st) == 0)
+				memcpy(&pkgstim, &st.st_mtim, sizeof(st.st_mtim));
+			else
+				memset(&pkgstim, 0, sizeof(pkgstim));
+
+			/* if the Packages file seems outdated, don't trust/use it */
+			if (fstat(ret->tree_fd, &st) != 0 ||
+					st.st_mtim.tv_sec < pkgstim.tv_sec ||  /* impossible? */
+					(st.st_mtim.tv_sec == pkgstim.tv_sec &&
+					 st.st_mtim.tv_nsec <= pkgstim.tv_nsec))
+				ret->cachetype = CACHE_PACKAGES;
+		}
 	}
 
 	return ret;


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2020-01-05 16:08 Fabian Groffen
  0 siblings, 0 replies; 23+ messages in thread
From: Fabian Groffen @ 2020-01-05 16:08 UTC (permalink / raw
  To: gentoo-commits

commit:     dc9f36140c34969f57e4fb3259315fedd1c61544
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Jan  5 15:21:02 2020 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Jan  5 15:59:25 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=dc9f3614

qfile/qlist: move away from tree_pkg_vdb_fopenat

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 TODO.md     |  1 +
 libq/tree.c | 33 +++++++--------------------------
 libq/tree.h | 21 ++++++---------------
 qfile.c     | 12 ++++++------
 qsize.c     | 24 +++++++++---------------
 5 files changed, 29 insertions(+), 62 deletions(-)

diff --git a/TODO.md b/TODO.md
index fe74cab..fc10f26 100644
--- a/TODO.md
+++ b/TODO.md
@@ -24,6 +24,7 @@
     or parsing Packages)
   - cached, such that repeated matches for the same thing are served off
     the cache (set), as frequently happens in dependency calculations
+  - tree\_{open,close}\_cat can be made static afterwards
 
 # qmerge
 - dep resolver needs spanktastic love.

diff --git a/libq/tree.c b/libq/tree.c
index 49b2fa1..0c05dc5 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -161,7 +161,7 @@ tree_close(tree_ctx *ctx)
 	free(ctx);
 }
 
-int
+static int
 tree_filter_cat(const struct dirent *de)
 {
 	int i;
@@ -230,7 +230,7 @@ tree_open_cat(tree_ctx *ctx, const char *name)
 	return cat_ctx;
 }
 
-tree_cat_ctx *
+static tree_cat_ctx *
 tree_next_cat(tree_ctx *ctx)
 {
 	/* search for a category directory */
@@ -295,7 +295,7 @@ tree_close_cat(tree_cat_ctx *cat_ctx)
 	free(cat_ctx);
 }
 
-int
+static int
 tree_filter_pkg(const struct dirent *de)
 {
 	int i;
@@ -527,29 +527,7 @@ tree_pkg_vdb_openat(
 	return openat(pkg_ctx->fd, file, flags | O_CLOEXEC, mode);
 }
 
-FILE *
-tree_pkg_vdb_fopenat(
-		tree_pkg_ctx *pkg_ctx,
-		const char *file,
-		int flags,
-		mode_t mode,
-		const char *fmode)
-{
-	FILE *fp;
-	int fd;
-
-	fd = tree_pkg_vdb_openat(pkg_ctx, file, flags, mode);
-	if (fd == -1)
-		return NULL;
-
-	fp = fdopen(fd, fmode);
-	if (!fp)
-		close(fd);
-
-	return fp;
-}
-
-bool
+static bool
 tree_pkg_vdb_eat(
 		tree_pkg_ctx *pkg_ctx,
 		const char *file,
@@ -721,6 +699,7 @@ tree_read_file_md5(tree_pkg_ctx *pkg_ctx)
 		assign_var(DEFINED_PHASES);
 		assign_var(REQUIRED_USE);
 		assign_var(BDEPEND);
+		assign_var(EPREFIX);
 		assign_var(_eclasses_);
 		assign_var(_md5_);
 		warn("Cache file for '%s/%s' has unknown key %s",
@@ -794,6 +773,7 @@ tree_read_file_ebuild(tree_pkg_ctx *pkg_ctx)
 			match_key(PDEPEND);
 			match_key(EAPI);
 			match_key(REQUIRED_USE);
+			match_key(BDEPEND);
 #undef match_key
 		}
 
@@ -899,6 +879,7 @@ tree_read_file_binpkg_xpak_cb(
 	match_path(BDEPEND);
 	match_path(CONTENTS);
 	match_path(USE);
+	match_path(EPREFIX);
 	match_path(repository);
 	else
 		return;

diff --git a/libq/tree.h b/libq/tree.h
index eb60296..c941172 100644
--- a/libq/tree.h
+++ b/libq/tree.h
@@ -89,16 +89,17 @@ struct tree_pkg_meta {
 	char *Q_PROVIDE;       /* line 14 */
 	char *Q_EAPI;
 	char *Q_PROPERTIES;
-	/* These are MD5-Cache only */
-	char *Q_DEFINED_PHASES;
-	char *Q_REQUIRED_USE;
 	char *Q_BDEPEND;
-	char *Q__eclasses_;
-	char *Q__md5_;
 	/* binpkgs/vdb */
+	char *Q_DEFINED_PHASES;
+	char *Q_REQUIRED_USE;
 	char *Q_CONTENTS;
 	char *Q_USE;
+	char *Q_EPREFIX;
 	char *Q_repository;
+	/* These are MD5-Cache only */
+	char *Q__eclasses_;
+	char *Q__md5_;
 };
 
 /* Metadata.xml */
@@ -116,20 +117,10 @@ tree_ctx *tree_open(const char *sroot, const char *portdir);
 tree_ctx *tree_open_vdb(const char *sroot, const char *svdb);
 tree_ctx *tree_open_binpkg(const char *sroot, const char *spkg);
 void tree_close(tree_ctx *ctx);
-int tree_filter_cat(const struct dirent *de);
 tree_cat_ctx *tree_open_cat(tree_ctx *ctx, const char *name);
-tree_cat_ctx *tree_next_cat(tree_ctx *ctx);
 void tree_close_cat(tree_cat_ctx *cat_ctx);
-int tree_filter_pkg(const struct dirent *de);
 tree_pkg_ctx *tree_open_pkg(tree_cat_ctx *cat_ctx, const char *name);
 tree_pkg_ctx *tree_next_pkg(tree_cat_ctx *cat_ctx);
-FILE *tree_pkg_vdb_fopenat(tree_pkg_ctx *pkg_ctx, const char *file,
-	int flags, mode_t mode, const char *fmode);
-#define tree_pkg_vdb_fopenat_ro(pkg_ctx, file) \
-	tree_pkg_vdb_fopenat(pkg_ctx, file, O_RDONLY, 0, "r")
-#define tree_pkg_vdb_fopenat_rw(pkg_ctx, file) \
-	tree_pkg_vdb_fopenat(pkg_ctx, file, O_RDWR | O_CREAT | O_TRUNC, 0644, "w")
-bool tree_pkg_vdb_eat(tree_pkg_ctx *pkg_ctx, const char *file, char **bufptr, size_t *buflen);
 tree_pkg_meta *tree_pkg_read(tree_pkg_ctx *pkg_ctx);
 void tree_close_meta(tree_pkg_meta *cache);
 char *tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t offset, const char *key);

diff --git a/qfile.c b/qfile.c
index 0b01061..3036be0 100644
--- a/qfile.c
+++ b/qfile.c
@@ -160,7 +160,8 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 	struct qfile_opt_state *state = priv;
 	const char *catname = pkg_ctx->cat_ctx->name;
 	qfile_args_t *args = &state->args;
-	FILE *fp;
+	char *line;
+	char *savep;
 	const char *base;
 	depend_atom *atom = NULL;
 	int i;
@@ -196,16 +197,16 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 	}
  dont_skip_pkg: /* End of the package exclusion tests. */
 
-	fp = tree_pkg_vdb_fopenat_ro(pkg_ctx, "CONTENTS");
-	if (fp == NULL)
+	line = tree_pkg_meta_get(pkg_ctx, CONTENTS);
+	if (line == NULL)
 		goto qlist_done;
 
 	/* Run through CONTENTS file */
-	while (getline(&state->buf, &state->buflen, fp) != -1) {
+	for (; (line = strtok_r(line, "\n", &savep)) != NULL; line = NULL) {
 		size_t dirname_len;
 		contents_entry *e;
 
-		e = contents_parse_line(state->buf);
+		e = contents_parse_line(line);
 		if (!e)
 			continue;
 
@@ -314,7 +315,6 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 			found++;
 		}
 	}
-	fclose(fp);
 
  qlist_done:
 	return found;

diff --git a/qsize.c b/qsize.c
index 617b50b..a25ce78 100644
--- a/qsize.c
+++ b/qsize.c
@@ -93,9 +93,6 @@ struct qsize_opt_state {
 	const char *fmt;
 	bool need_full_atom:1;
 
-	size_t buflen;
-	char *buf;
-
 	size_t num_all_files, num_all_nonfiles, num_all_ignored;
 	uint64_t num_all_bytes;
 };
@@ -106,28 +103,30 @@ qsize_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 	struct qsize_opt_state *state = priv;
 	size_t i;
 	depend_atom *atom;
-	FILE *fp;
+	char *line;
+	char *savep;
 	size_t num_files, num_nonfiles, num_ignored;
 	uint64_t num_bytes;
 
-	if ((fp = tree_pkg_vdb_fopenat_ro(pkg_ctx, "CONTENTS")) == NULL)
+	if ((line = tree_pkg_meta_get(pkg_ctx, CONTENTS)) == NULL)
 		return EXIT_SUCCESS;
 
 	num_ignored = num_files = num_nonfiles = num_bytes = 0;
-	while (getline(&state->buf, &state->buflen, fp) != -1) {
+	for (; (line = strtok_r(line, "\n", &savep)) != NULL; line = NULL) {
 		contents_entry *e;
 		regex_t *regex;
 		int ok = 0;
 
-		e = contents_parse_line(state->buf);
+		e = contents_parse_line(line);
 		if (!e)
 			continue;
 
-		array_for_each(state->ignore_regexp, i, regex)
-			if (!regexec(regex, state->buf, 0, NULL, 0)) {
-				num_ignored += 1;
+		array_for_each(state->ignore_regexp, i, regex) {
+			if (!regexec(regex, e->name, 0, NULL, 0)) {
+				num_ignored++;
 				ok = 1;
 			}
+		}
 		if (ok)
 			continue;
 
@@ -141,7 +140,6 @@ qsize_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 		} else
 			++num_nonfiles;
 	}
-	fclose(fp);
 	state->num_all_bytes += num_bytes;
 	state->num_all_files += num_files;
 	state->num_all_nonfiles += num_nonfiles;
@@ -227,9 +225,6 @@ int qsize_main(int argc, char **argv)
 			state.fmt = "%[CATEGORY]%[PN]";
 	}
 
-	state.buflen = _Q_PATH_MAX;
-	state.buf = xmalloc(state.buflen);
-
 	vdb = tree_open_vdb(portroot, portvdb);
 	if (vdb != NULL) {
 		if (array_cnt(atoms) > 0) {
@@ -257,7 +252,6 @@ int qsize_main(int argc, char **argv)
 		atom_implode(atom);
 	xarrayfree_int(state.atoms);
 	xarrayfree(state.ignore_regexp);
-	free(state.buf);
 
 	return ret;
 }


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2020-05-16 18:27 Fabian Groffen
  0 siblings, 0 replies; 23+ messages in thread
From: Fabian Groffen @ 2020-05-16 18:27 UTC (permalink / raw
  To: gentoo-commits

commit:     dcab7ec282cfb8827a95c59c51322271d14d91c4
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat May 16 18:24:45 2020 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat May 16 18:24:45 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=dcab7ec2

libq/hash: unify hash methods into single approach

remove duplicate hashing strategies, use private copies of md5 and sha1
hashes when ssl is not available, else rely on ssl to provide hashing
capabilities

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 Makefile.am                         |  11 +--
 Makefile.in                         |  50 +++++------
 libq/Makefile.am                    |   8 +-
 libq/Makefile.in                    |  93 ++++++++------------
 libq/hash.c                         | 165 +++++++++++++++++++++++++++++++++---
 libq/hash.h                         |  34 ++++++--
 libq/hash_fd.h                      |  13 ---
 libq/{hash_fd.c => hash_md5_sha1.c} | 125 ++-------------------------
 libq/hash_md5_sha1.h                |  35 ++++++++
 libq/md5_sha1_sum.c                 |  93 --------------------
 libq/md5_sha1_sum.h                 |  24 ------
 qcheck.c                            |  10 +--
 qmerge.c                            |  14 ++-
 qpkg.c                              |   7 +-
 14 files changed, 301 insertions(+), 381 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 3107bda..ceded24 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -69,10 +69,12 @@ q_CPPFLAGS = \
 	-I$(top_srcdir)/libq \
 	-I$(top_builddir)/autotools/gnulib \
 	-I$(top_srcdir)/autotools/gnulib \
+	$(OPENMP_CFLAGS) \
 	$(NULL)
 q_LDADD = \
 	$(top_builddir)/libq/libq.la \
 	$(top_builddir)/autotools/gnulib/libgnu.a \
+	$(OPENMP_CFLAGS) \
 	$(LIBSSL) \
 	$(LIBBL2) \
 	$(LIBZ) \
@@ -84,21 +86,12 @@ q_LDADD = \
 if QMANIFEST_ENABLED
 q_SOURCES += qmanifest.c
 q_CPPFLAGS += \
-	$(OPENMP_CFLAGS) \
 	$(GPGME_CFLAGS)
-q_LDADD += \
-	$(OPENMP_CFLAGS)
 dist_man_MANS += man/qmanifest.1
 APPLETS += qmanifest
 endif
 if QTEGRITY_ENABLED
 q_SOURCES += qtegrity.c
-if !QMANIFEST_ENABLED
-q_CPPFLAGS += \
-	$(OPENMP_CFLAGS)
-q_LDADD += \
-	$(OPENMP_CFLAGS)
-endif
 dist_man_MANS += man/qtegrity.1
 APPLETS += qtegrity
 endif

diff --git a/Makefile.in b/Makefile.in
index 7403b5b..91d9a3b 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -91,23 +91,13 @@ host_triplet = @host@
 bin_PROGRAMS = q$(EXEEXT)
 @QMANIFEST_ENABLED_TRUE@am__append_1 = qmanifest.c
 @QMANIFEST_ENABLED_TRUE@am__append_2 = \
-@QMANIFEST_ENABLED_TRUE@	$(OPENMP_CFLAGS) \
 @QMANIFEST_ENABLED_TRUE@	$(GPGME_CFLAGS)
 
-@QMANIFEST_ENABLED_TRUE@am__append_3 = \
-@QMANIFEST_ENABLED_TRUE@	$(OPENMP_CFLAGS)
-
-@QMANIFEST_ENABLED_TRUE@am__append_4 = man/qmanifest.1
-@QMANIFEST_ENABLED_TRUE@am__append_5 = qmanifest
-@QTEGRITY_ENABLED_TRUE@am__append_6 = qtegrity.c
-@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_TRUE@am__append_7 = \
-@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_TRUE@	$(OPENMP_CFLAGS)
-
-@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_TRUE@am__append_8 = \
-@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_TRUE@	$(OPENMP_CFLAGS)
-
-@QTEGRITY_ENABLED_TRUE@am__append_9 = man/qtegrity.1
-@QTEGRITY_ENABLED_TRUE@am__append_10 = qtegrity
+@QMANIFEST_ENABLED_TRUE@am__append_3 = man/qmanifest.1
+@QMANIFEST_ENABLED_TRUE@am__append_4 = qmanifest
+@QTEGRITY_ENABLED_TRUE@am__append_5 = qtegrity.c
+@QTEGRITY_ENABLED_TRUE@am__append_6 = man/qtegrity.1
+@QTEGRITY_ENABLED_TRUE@am__append_7 = qtegrity
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/autotools/m4/00gnulib.m4 \
@@ -278,14 +268,12 @@ am_q_OBJECTS = q-main.$(OBJEXT) q-q.$(OBJEXT) q-qatom.$(OBJEXT) \
 	$(am__objects_2)
 q_OBJECTS = $(am_q_OBJECTS)
 am__DEPENDENCIES_1 =
-@QMANIFEST_ENABLED_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
-@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_TRUE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1)
 q_DEPENDENCIES = $(top_builddir)/libq/libq.la \
 	$(top_builddir)/autotools/gnulib/libgnu.a \
 	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
 	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
 	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
-	$(am__DEPENDENCIES_2) $(am__DEPENDENCIES_3)
+	$(am__DEPENDENCIES_1)
 AM_V_lt = $(am__v_lt_@AM_V@)
 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
 am__v_lt_0 = --silent
@@ -1598,21 +1586,29 @@ SUBDIRS = \
 
 APPLETS = q qatom qcheck qdepends qfile qgrep qkeyword qlist qlop \
 	qmerge qpkg qsearch qsize qtbz2 quse qxpak $(NULL) \
-	$(am__append_5) $(am__append_10)
+	$(am__append_4) $(am__append_7)
 dist_man_MANS = man/q.1 man/qatom.1 man/qcheck.1 man/qdepends.1 \
 	man/qfile.1 man/qgrep.1 man/qkeyword.1 man/qlist.1 man/qlop.1 \
 	man/qmerge.1 man/qpkg.1 man/qsearch.1 man/qsize.1 man/qtbz2.1 \
-	man/quse.1 man/qxpak.1 $(NULL) $(am__append_4) $(am__append_9)
+	man/quse.1 man/qxpak.1 $(NULL) $(am__append_3) $(am__append_6)
 q_SOURCES = main.c q.c qatom.c qcheck.c qdepends.c qfile.c qgrep.c \
 	qkeyword.c qlist.c qlop.c qmerge.c qpkg.c qsearch.c qsize.c \
-	qtbz2.c quse.c qxpak.c $(NULL) $(am__append_1) $(am__append_6)
+	qtbz2.c quse.c qxpak.c $(NULL) $(am__append_1) $(am__append_5)
 q_CPPFLAGS = -I$(top_srcdir)/libq -I$(top_builddir)/autotools/gnulib \
-	-I$(top_srcdir)/autotools/gnulib $(NULL) $(am__append_2) \
-	$(am__append_7)
-q_LDADD = $(top_builddir)/libq/libq.la \
-	$(top_builddir)/autotools/gnulib/libgnu.a $(LIBSSL) $(LIBBL2) \
-	$(LIBZ) $(GPGME_LIBS) $(LIB_CLOCK_GETTIME) $(LIB_EACCESS) \
-	$(NULL) $(am__append_3) $(am__append_8)
+	-I$(top_srcdir)/autotools/gnulib $(OPENMP_CFLAGS) $(NULL) \
+	$(am__append_2)
+q_LDADD = \
+	$(top_builddir)/libq/libq.la \
+	$(top_builddir)/autotools/gnulib/libgnu.a \
+	$(OPENMP_CFLAGS) \
+	$(LIBSSL) \
+	$(LIBBL2) \
+	$(LIBZ) \
+	$(GPGME_LIBS) \
+	$(LIB_CLOCK_GETTIME) \
+	$(LIB_EACCESS) \
+	$(NULL)
+
 EXTRA_DIST = \
 	autotools/m4/gnulib-cache.m4 \
 	applets.h \

diff --git a/libq/Makefile.am b/libq/Makefile.am
index 9cb19a2..da100b6 100644
--- a/libq/Makefile.am
+++ b/libq/Makefile.am
@@ -9,10 +9,8 @@ QFILES = \
 	dep.c dep.h \
 	eat_file.c eat_file.h \
 	hash.c hash.h \
-	hash_fd.c hash_fd.h \
 	human_readable.c human_readable.h \
 	i18n.h \
-	md5_sha1_sum.c md5_sha1_sum.h \
 	prelink.c prelink.h \
 	profile.c profile.h \
 	rmspace.c rmspace.h \
@@ -29,6 +27,12 @@ QFILES = \
 	xsystem.c xsystem.h \
 	$(NULL)
 
+if !QMANIFEST_ENABLED
+if !QTEGRITY_ENABLED
+QFILES += hash_md5_sha1.c hash_md5_sha1.h
+endif
+endif
+
 noinst_LTLIBRARIES = libq.la
 libq_la_SOURCES = $(QFILES)
 libq_la_CPPFLAGS = \

diff --git a/libq/Makefile.in b/libq/Makefile.in
index cb5fa51..696d469 100644
--- a/libq/Makefile.in
+++ b/libq/Makefile.in
@@ -88,6 +88,7 @@ PRE_UNINSTALL = :
 POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
+@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_FALSE@am__append_1 = hash_md5_sha1.c hash_md5_sha1.h
 subdir = libq
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/autotools/m4/00gnulib.m4 \
@@ -241,16 +242,25 @@ CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
 LTLIBRARIES = $(noinst_LTLIBRARIES)
 libq_la_LIBADD =
-am__objects_1 = libq_la-atom.lo libq_la-basename.lo libq_la-colors.lo \
+am__libq_la_SOURCES_DIST = atom.c atom.h basename.c basename.h \
+	busybox.h colors.c colors.h contents.c contents.h copy_file.c \
+	copy_file.h dep.c dep.h eat_file.c eat_file.h hash.c hash.h \
+	human_readable.c human_readable.h i18n.h prelink.c prelink.h \
+	profile.c profile.h rmspace.c rmspace.h safe_io.c safe_io.h \
+	scandirat.c scandirat.h set.c set.h tree.c tree.h xarray.c \
+	xarray.h xasprintf.h xchdir.c xchdir.h xmkdir.c xmkdir.h \
+	xpak.c xpak.h xregex.c xregex.h xsystem.c xsystem.h \
+	hash_md5_sha1.c hash_md5_sha1.h
+@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_FALSE@am__objects_1 = libq_la-hash_md5_sha1.lo
+am__objects_2 = libq_la-atom.lo libq_la-basename.lo libq_la-colors.lo \
 	libq_la-contents.lo libq_la-copy_file.lo libq_la-dep.lo \
-	libq_la-eat_file.lo libq_la-hash.lo libq_la-hash_fd.lo \
-	libq_la-human_readable.lo libq_la-md5_sha1_sum.lo \
+	libq_la-eat_file.lo libq_la-hash.lo libq_la-human_readable.lo \
 	libq_la-prelink.lo libq_la-profile.lo libq_la-rmspace.lo \
 	libq_la-safe_io.lo libq_la-scandirat.lo libq_la-set.lo \
 	libq_la-tree.lo libq_la-xarray.lo libq_la-xchdir.lo \
 	libq_la-xmkdir.lo libq_la-xpak.lo libq_la-xregex.lo \
-	libq_la-xsystem.lo
-am_libq_la_OBJECTS = $(am__objects_1)
+	libq_la-xsystem.lo $(am__objects_1)
+am_libq_la_OBJECTS = $(am__objects_2)
 libq_la_OBJECTS = $(am_libq_la_OBJECTS)
 AM_V_lt = $(am__v_lt_@AM_V@)
 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@@ -277,9 +287,8 @@ am__depfiles_remade = ./$(DEPDIR)/libq_la-atom.Plo \
 	./$(DEPDIR)/libq_la-contents.Plo \
 	./$(DEPDIR)/libq_la-copy_file.Plo ./$(DEPDIR)/libq_la-dep.Plo \
 	./$(DEPDIR)/libq_la-eat_file.Plo ./$(DEPDIR)/libq_la-hash.Plo \
-	./$(DEPDIR)/libq_la-hash_fd.Plo \
+	./$(DEPDIR)/libq_la-hash_md5_sha1.Plo \
 	./$(DEPDIR)/libq_la-human_readable.Plo \
-	./$(DEPDIR)/libq_la-md5_sha1_sum.Plo \
 	./$(DEPDIR)/libq_la-prelink.Plo \
 	./$(DEPDIR)/libq_la-profile.Plo \
 	./$(DEPDIR)/libq_la-rmspace.Plo \
@@ -309,7 +318,7 @@ am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
 am__v_CCLD_0 = @echo "  CCLD    " $@;
 am__v_CCLD_1 = 
 SOURCES = $(libq_la_SOURCES)
-DIST_SOURCES = $(libq_la_SOURCES)
+DIST_SOURCES = $(am__libq_la_SOURCES_DIST)
 am__can_run_installinfo = \
   case $$AM_UPDATE_INFO_DIR in \
     n|no|NO) false;; \
@@ -1470,36 +1479,14 @@ target_alias = @target_alias@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
-QFILES = \
-	atom.c atom.h \
-	basename.c basename.h \
-	busybox.h \
-	colors.c colors.h \
-	contents.c contents.h \
-	copy_file.c copy_file.h \
-	dep.c dep.h \
-	eat_file.c eat_file.h \
-	hash.c hash.h \
-	hash_fd.c hash_fd.h \
-	human_readable.c human_readable.h \
-	i18n.h \
-	md5_sha1_sum.c md5_sha1_sum.h \
-	prelink.c prelink.h \
-	profile.c profile.h \
-	rmspace.c rmspace.h \
-	safe_io.c safe_io.h \
-	scandirat.c scandirat.h \
-	set.c set.h \
-	tree.c tree.h \
-	xarray.c xarray.h \
-	xasprintf.h \
-	xchdir.c xchdir.h \
-	xmkdir.c xmkdir.h \
-	xpak.c xpak.h \
-	xregex.c xregex.h \
-	xsystem.c xsystem.h \
-	$(NULL)
-
+QFILES = atom.c atom.h basename.c basename.h busybox.h colors.c \
+	colors.h contents.c contents.h copy_file.c copy_file.h dep.c \
+	dep.h eat_file.c eat_file.h hash.c hash.h human_readable.c \
+	human_readable.h i18n.h prelink.c prelink.h profile.c \
+	profile.h rmspace.c rmspace.h safe_io.c safe_io.h scandirat.c \
+	scandirat.h set.c set.h tree.c tree.h xarray.c xarray.h \
+	xasprintf.h xchdir.c xchdir.h xmkdir.c xmkdir.h xpak.c xpak.h \
+	xregex.c xregex.h xsystem.c xsystem.h $(NULL) $(am__append_1)
 noinst_LTLIBRARIES = libq.la
 libq_la_SOURCES = $(QFILES)
 libq_la_CPPFLAGS = \
@@ -1569,9 +1556,8 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-dep.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-eat_file.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-hash.Plo@am__quote@ # am--include-marker
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-hash_fd.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-hash_md5_sha1.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-human_readable.Plo@am__quote@ # am--include-marker
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-md5_sha1_sum.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-prelink.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-profile.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-rmspace.Plo@am__quote@ # am--include-marker
@@ -1669,13 +1655,6 @@ libq_la-hash.lo: hash.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-hash.lo `test -f 'hash.c' || echo '$(srcdir)/'`hash.c
 
-libq_la-hash_fd.lo: hash_fd.c
-@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libq_la-hash_fd.lo -MD -MP -MF $(DEPDIR)/libq_la-hash_fd.Tpo -c -o libq_la-hash_fd.lo `test -f 'hash_fd.c' || echo '$(srcdir)/'`hash_fd.c
-@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-hash_fd.Tpo $(DEPDIR)/libq_la-hash_fd.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='hash_fd.c' object='libq_la-hash_fd.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-hash_fd.lo `test -f 'hash_fd.c' || echo '$(srcdir)/'`hash_fd.c
-
 libq_la-human_readable.lo: human_readable.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libq_la-human_readable.lo -MD -MP -MF $(DEPDIR)/libq_la-human_readable.Tpo -c -o libq_la-human_readable.lo `test -f 'human_readable.c' || echo '$(srcdir)/'`human_readable.c
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-human_readable.Tpo $(DEPDIR)/libq_la-human_readable.Plo
@@ -1683,13 +1662,6 @@ libq_la-human_readable.lo: human_readable.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-human_readable.lo `test -f 'human_readable.c' || echo '$(srcdir)/'`human_readable.c
 
-libq_la-md5_sha1_sum.lo: md5_sha1_sum.c
-@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libq_la-md5_sha1_sum.lo -MD -MP -MF $(DEPDIR)/libq_la-md5_sha1_sum.Tpo -c -o libq_la-md5_sha1_sum.lo `test -f 'md5_sha1_sum.c' || echo '$(srcdir)/'`md5_sha1_sum.c
-@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-md5_sha1_sum.Tpo $(DEPDIR)/libq_la-md5_sha1_sum.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='md5_sha1_sum.c' object='libq_la-md5_sha1_sum.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-md5_sha1_sum.lo `test -f 'md5_sha1_sum.c' || echo '$(srcdir)/'`md5_sha1_sum.c
-
 libq_la-prelink.lo: prelink.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libq_la-prelink.lo -MD -MP -MF $(DEPDIR)/libq_la-prelink.Tpo -c -o libq_la-prelink.lo `test -f 'prelink.c' || echo '$(srcdir)/'`prelink.c
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-prelink.Tpo $(DEPDIR)/libq_la-prelink.Plo
@@ -1781,6 +1753,13 @@ libq_la-xsystem.lo: xsystem.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-xsystem.lo `test -f 'xsystem.c' || echo '$(srcdir)/'`xsystem.c
 
+libq_la-hash_md5_sha1.lo: hash_md5_sha1.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libq_la-hash_md5_sha1.lo -MD -MP -MF $(DEPDIR)/libq_la-hash_md5_sha1.Tpo -c -o libq_la-hash_md5_sha1.lo `test -f 'hash_md5_sha1.c' || echo '$(srcdir)/'`hash_md5_sha1.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-hash_md5_sha1.Tpo $(DEPDIR)/libq_la-hash_md5_sha1.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='hash_md5_sha1.c' object='libq_la-hash_md5_sha1.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-hash_md5_sha1.lo `test -f 'hash_md5_sha1.c' || echo '$(srcdir)/'`hash_md5_sha1.c
+
 mostlyclean-libtool:
 	-rm -f *.lo
 
@@ -1920,9 +1899,8 @@ distclean: distclean-am
 	-rm -f ./$(DEPDIR)/libq_la-dep.Plo
 	-rm -f ./$(DEPDIR)/libq_la-eat_file.Plo
 	-rm -f ./$(DEPDIR)/libq_la-hash.Plo
-	-rm -f ./$(DEPDIR)/libq_la-hash_fd.Plo
+	-rm -f ./$(DEPDIR)/libq_la-hash_md5_sha1.Plo
 	-rm -f ./$(DEPDIR)/libq_la-human_readable.Plo
-	-rm -f ./$(DEPDIR)/libq_la-md5_sha1_sum.Plo
 	-rm -f ./$(DEPDIR)/libq_la-prelink.Plo
 	-rm -f ./$(DEPDIR)/libq_la-profile.Plo
 	-rm -f ./$(DEPDIR)/libq_la-rmspace.Plo
@@ -1989,9 +1967,8 @@ maintainer-clean: maintainer-clean-am
 	-rm -f ./$(DEPDIR)/libq_la-dep.Plo
 	-rm -f ./$(DEPDIR)/libq_la-eat_file.Plo
 	-rm -f ./$(DEPDIR)/libq_la-hash.Plo
-	-rm -f ./$(DEPDIR)/libq_la-hash_fd.Plo
+	-rm -f ./$(DEPDIR)/libq_la-hash_md5_sha1.Plo
 	-rm -f ./$(DEPDIR)/libq_la-human_readable.Plo
-	-rm -f ./$(DEPDIR)/libq_la-md5_sha1_sum.Plo
 	-rm -f ./$(DEPDIR)/libq_la-prelink.Plo
 	-rm -f ./$(DEPDIR)/libq_la-profile.Plo
 	-rm -f ./$(DEPDIR)/libq_la-rmspace.Plo

diff --git a/libq/hash.c b/libq/hash.c
index 6d0a62b..a174a0c 100644
--- a/libq/hash.c
+++ b/libq/hash.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018-2019 Gentoo Foundation
+ * Copyright 2018-2020 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
@@ -13,11 +13,14 @@
 #include "main.h"
 
 #ifdef HAVE_SSL
-#include <openssl/sha.h>
-#include <openssl/whrlpool.h>
+# include <openssl/md5.h>
+# include <openssl/sha.h>
+# include <openssl/whrlpool.h>
+#else
+# include "hash_md5_sha1.h"
 #endif
 #ifdef HAVE_BLAKE2B
-#include <blake2.h>
+# include <blake2.h>
 #endif
 
 #include "hash.h"
@@ -26,6 +29,28 @@ void
 hash_hex(char *out, const unsigned char *buf, const int length)
 {
 	switch (length) {
+		/* MD5_DIGEST_LENGTH */
+		case 16:
+			snprintf(out, 32 + 1,
+					"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
+					"%02x%02x%02x%02x%02x%02x",
+					buf[ 0], buf[ 1], buf[ 2], buf[ 3], buf[ 4],
+					buf[ 5], buf[ 6], buf[ 7], buf[ 8], buf[ 9],
+					buf[10], buf[11], buf[12], buf[13], buf[14],
+					buf[15]
+					);
+			break;
+		/* SHA1_DIGEST_LENGTH */
+		case 20:
+			snprintf(out, 40 + 1,
+					"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
+					"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
+					buf[ 0], buf[ 1], buf[ 2], buf[ 3], buf[ 4],
+					buf[ 5], buf[ 6], buf[ 7], buf[ 8], buf[ 9],
+					buf[10], buf[11], buf[12], buf[13], buf[14],
+					buf[15], buf[16], buf[17], buf[18], buf[19]
+					);
+			break;
 		/* SHA256_DIGEST_LENGTH */
 		case 32:
 			snprintf(out, 64 + 1,
@@ -89,8 +114,10 @@ hash_hex(char *out, const unsigned char *buf, const int length)
  * the file pointed to by fname is returned in the flen argument.
  */
 void
-hash_compute_file(
-		const char *fname,
+hash_multiple_file_fd(
+		int fd,
+		char *md5,
+		char *sha1,
 		char *sha256,
 		char *sha512,
 		char *whrlpl,
@@ -102,10 +129,14 @@ hash_compute_file(
 	char data[8192];
 	size_t len;
 #ifdef HAVE_SSL
+	MD5_CTX m5;
+	SHA_CTX s1;
 	SHA256_CTX s256;
 	SHA512_CTX s512;
 	WHIRLPOOL_CTX whrl;
 #else
+	struct md5_ctx_t m5;
+	struct sha1_ctx_t s1;
 	(void)sha256;
 	(void)sha512;
 	(void)whrlpl;
@@ -116,13 +147,18 @@ hash_compute_file(
 	(void)blak2b;
 #endif
 
-	if ((f = fopen(fname, "r")) == NULL)
+	if ((f = fdopen(fd, "r")) == NULL)
 		return;
 
 #ifdef HAVE_SSL
+	MD5_Init(&m5);
+	SHA1_Init(&s1);
 	SHA256_Init(&s256);
 	SHA512_Init(&s512);
 	WHIRLPOOL_Init(&whrl);
+#else
+	md5_begin(&m5);
+	sha1_begin(&s1);
 #endif
 #ifdef HAVE_BLAKE2B
 	blake2b_init(&bl2b, BLAKE2B_OUTBYTES);
@@ -130,10 +166,19 @@ hash_compute_file(
 
 	while ((len = fread(data, 1, sizeof(data), f)) > 0) {
 		*flen += len;
-#if defined(HAVE_SSL) || defined(HAVE_BLAKE2B)
 #pragma omp parallel sections
 		{
 #ifdef HAVE_SSL
+#pragma omp section
+			{
+				if (hashes & HASH_MD5)
+					MD5_Update(&m5, data, len);
+			}
+#pragma omp section
+			{
+				if (hashes & HASH_SHA1)
+					SHA1_Update(&s1, data, len);
+			}
 #pragma omp section
 			{
 				if (hashes & HASH_SHA256)
@@ -149,6 +194,17 @@ hash_compute_file(
 				if (hashes & HASH_WHIRLPOOL)
 					WHIRLPOOL_Update(&whrl, data, len);
 			}
+#else
+#pragma omp section
+			{
+				if (hashes & HASH_MD5)
+					md5_hash(data, len, &m5);
+			}
+#pragma omp section
+			{
+				if (hashes & HASH_SHA1)
+					sha1_hash(data, len, &s1);
+			}
 #endif
 #ifdef HAVE_BLAKE2B
 #pragma omp section
@@ -158,14 +214,29 @@ hash_compute_file(
 			}
 #endif
 		}
-#endif /* HAVE_SSL || HAVE_BLAKE2B */
 	}
 	fclose(f);
 
-#if defined(HAVE_SSL) || defined(HAVE_BLAKE2B)
 #pragma omp parallel sections
 	{
 #ifdef HAVE_SSL
+#pragma omp section
+		{
+			if (hashes & HASH_MD5) {
+				unsigned char md5buf[MD5_DIGEST_LENGTH];
+				MD5_Final(md5buf, &m5);
+				hash_hex(md5, md5buf, MD5_DIGEST_LENGTH);
+			}
+		}
+#pragma omp section
+		{
+			if (hashes & HASH_SHA1) {
+				unsigned char sha1buf[SHA_DIGEST_LENGTH];
+				SHA1_Final(sha1buf, &s1);
+				hash_hex(sha1, sha1buf, SHA_DIGEST_LENGTH);
+			}
+		}
+#pragma omp section
 		{
 			if (hashes & HASH_SHA256) {
 				unsigned char sha256buf[SHA256_DIGEST_LENGTH];
@@ -189,6 +260,23 @@ hash_compute_file(
 				hash_hex(whrlpl, whrlplbuf, WHIRLPOOL_DIGEST_LENGTH);
 			}
 		}
+#else
+#pragma omp section
+		{
+			if (hashes & HASH_MD5) {
+				unsigned char md5buf[16];
+				md5_end(md5buf, &m5);
+				hash_hex(md5, md5buf, 16);
+			}
+		}
+#pragma omp section
+		{
+			if (hashes & HASH_SHA1) {
+				unsigned char sha1buf[20];
+				sha1_end(sha1buf, &s1);
+				hash_hex(sha1, sha1buf, 20);
+			}
+		}
 #endif
 #ifdef HAVE_BLAKE2B
 #pragma omp section
@@ -201,5 +289,60 @@ hash_compute_file(
 		}
 #endif
 	}
-#endif /* HAVE_SSL || HAVE_BLAKE2B */
+
+	fclose(f);
+}
+
+void
+hash_multiple_file_at_cb(
+		int pfd,
+		const char *fname,
+		hash_cb_t cb,
+		char *md5,
+		char *sha1,
+		char *sha256,
+		char *sha512,
+		char *whrlpl,
+		char *blak2b,
+		size_t *flen,
+		int hashes)
+{
+	int fd = openat(pfd, fname, O_RDONLY | O_CLOEXEC);
+	if (fd == -1) {
+		*flen = 0;
+		return;
+	}
+
+	if (cb != NULL)
+		fd = cb(fd, fname);
+
+	hash_multiple_file_fd(fd, md5, sha1, sha256, sha512,
+			whrlpl, blak2b, flen, hashes);
+
+	close(fd);
+}
+
+static char _hash_file_buf[128 + 1];
+char *
+hash_file_at_cb(int pfd, const char *fname, int hash, hash_cb_t cb)
+{
+	size_t dummy;
+
+	switch (hash) {
+		case HASH_MD5:
+		case HASH_SHA1:
+		case HASH_SHA256:
+		case HASH_SHA512:
+		case HASH_WHIRLPOOL:
+		case HASH_BLAKE2B:
+			hash_multiple_file_at_cb(pfd, fname, cb,
+					_hash_file_buf, _hash_file_buf, _hash_file_buf,
+					_hash_file_buf, _hash_file_buf, _hash_file_buf,
+					&dummy, hash);
+			break;
+		default:
+			return NULL;
+	}
+
+	return _hash_file_buf;
 }

diff --git a/libq/hash.h b/libq/hash.h
index 89f3841..204da5f 100644
--- a/libq/hash.h
+++ b/libq/hash.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018-2019 Gentoo Foundation
+ * Copyright 2018-2020 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
@@ -8,19 +8,41 @@
 #ifndef _HASH_H
 #define _HASH_H 1
 
+/* for AT_FDCWD */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
 enum hash_impls {
-	HASH_SHA256    = 1<<0,
-	HASH_SHA512    = 1<<1,
-	HASH_WHIRLPOOL = 1<<2,
-	HASH_BLAKE2B   = 1<<3
+	HASH_MD5       = 1<<0,
+	HASH_SHA1      = 1<<1,
+	HASH_SHA256    = 1<<2,
+	HASH_SHA512    = 1<<3,
+	HASH_WHIRLPOOL = 1<<4,
+	HASH_BLAKE2B   = 1<<5
 };
 
 /* default changed from sha256, sha512, whirlpool
  * to blake2b, sha512 on 2017-11-21 */
 #define HASH_DEFAULT  (HASH_BLAKE2B | HASH_SHA512);
 
+/* pass in a fd and get back a fd; filename is for display only */
+typedef int (*hash_cb_t) (int, const char *);
+
 void hash_hex(char *out, const unsigned char *buf, const int length);
-void hash_compute_file(const char *fname, char *sha256, char *sha512,
+void hash_multiple_file_fd(
+		int fd, char *md5, char *sha1, char *sha256, char *sha512,
 		char *whrlpl, char *blak2b, size_t *flen, int hashes);
+void hash_multiple_file_at_cb(
+		int pfd, const char *fname, hash_cb_t cb, char *md5,
+		char *sha1, char *sha256, char *sha512, char *whrlpl,
+		char *blak2b, size_t *flen, int hashes);
+#define hash_multiple_file(f, m, s1, s2, s5, w, b, l, h) \
+	hash_multiple_file_at_cb(AT_FDCWD, f, NULL, m, s1, s2, s5, w, b, l, h)
+#define hash_compute_file(f, s2, s5, w, b, l, h) \
+	hash_multiple_file_at_cb(AT_FDCWD, f, NULL, NULL, NULL, s2, s5, w, b, l, h)
+char *hash_file_at_cb(int pfd, const char *filename, int hash_algo, hash_cb_t cb);
+#define hash_file(f, h) hash_file_at_cb(AT_FDCWD, f, h, NULL)
+#define hash_file_at(fd, f, h) hash_file_at_cb(fd, f, h, NULL)
 
 #endif

diff --git a/libq/hash_fd.h b/libq/hash_fd.h
deleted file mode 100644
index 37d21b2..0000000
--- a/libq/hash_fd.h
+++ /dev/null
@@ -1,13 +0,0 @@
-
-/*
- * Copyright 2005-2019 Gentoo Foundation
- * Distributed under the terms of the GNU General Public License v2
- */
-
-#ifndef _HASH_FD_H
-#define _HASH_FD_H 1
-
-int hash_fd(int src_fd, const size_t size, const uint8_t hash_algo,
-				   uint8_t * hashval);
-
-#endif

diff --git a/libq/hash_fd.c b/libq/hash_md5_sha1.c
similarity index 89%
rename from libq/hash_fd.c
rename to libq/hash_md5_sha1.c
index 9c47078..bdbe0db 100644
--- a/libq/hash_fd.c
+++ b/libq/hash_md5_sha1.c
@@ -53,11 +53,9 @@
 # endif
 #endif
 
-#include "busybox.h"
 #include "xalloc.h"
-#include "hash_fd.h"
+#include "hash_md5_sha1.h"
 
-#ifdef CONFIG_SHA1SUM
 /*
  ---------------------------------------------------------------------------
  Begin Dr. Gladman's sha1 code
@@ -129,13 +127,6 @@
     t = a; a = rotl32(a,5) + f(b,c,d) + e + k + w[i]; \
     e = d; d = c; c = rotl32(b, 30); b = t
 
-/* type to hold the SHA1 context  */
-struct sha1_ctx_t {
-	uint32_t count[2];
-	uint32_t hash[5];
-	uint32_t wbuf[16];
-};
-
 static void sha1_compile(struct sha1_ctx_t *ctx)
 {
 	uint32_t w[80], i, a, b, c, d, e, t;
@@ -178,7 +169,7 @@ static void sha1_compile(struct sha1_ctx_t *ctx)
 	ctx->hash[4] += e;
 }
 
-static void sha1_begin(struct sha1_ctx_t *ctx)
+void sha1_begin(struct sha1_ctx_t *ctx)
 {
 	ctx->count[0] = ctx->count[1] = 0;
 	ctx->hash[0] = 0x67452301;
@@ -190,7 +181,7 @@ static void sha1_begin(struct sha1_ctx_t *ctx)
 
 /* SHA1 hash data in an array of bytes into hash buffer and call the        */
 /* hash_compile function as required.                                       */
-static void sha1_hash(const void *data, size_t len, void *ctx_v)
+void sha1_hash(const void *data, size_t len, void *ctx_v)
 {
 	struct sha1_ctx_t *ctx = (struct sha1_ctx_t *) ctx_v;
 	uint32_t pos = (uint32_t) (ctx->count[0] & SHA1_MASK);
@@ -221,7 +212,7 @@ static uint32_t mask[4] = { 0x00000000, 0xff000000, 0xffff0000, 0xffffff00 };
 static uint32_t bits[4] = { 0x80000000, 0x00800000, 0x00008000, 0x00000080 };
 # endif /* __BYTE_ORDER */
 
-static void sha1_end(unsigned char hval[], struct sha1_ctx_t *ctx)
+void sha1_end(unsigned char hval[], struct sha1_ctx_t *ctx)
 {
 	uint32_t i, cnt = (uint32_t) (ctx->count[0] & SHA1_MASK);
 
@@ -267,9 +258,7 @@ static void sha1_end(unsigned char hval[], struct sha1_ctx_t *ctx)
  End of Dr. Gladman's sha1 code
  ---------------------------------------------------------------------------
 */
-#endif	/* CONFIG_SHA1 */
 
-#ifdef CONFIG_MD5SUM
 /*
  * md5sum.c - Compute MD5 checksum of files or strings according to the
  *            definition of MD5 in RFC 1321 from April 1992.
@@ -310,21 +299,10 @@ static void sha1_end(unsigned char hval[], struct sha1_ctx_t *ctx)
 static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ...  */  };
 # endif	/* MD5SUM_SIZE_VS_SPEED == 0 */
 
-/* Structure to save state of computation between the single steps.  */
-struct md5_ctx_t {
-	uint32_t A;
-	uint32_t B;
-	uint32_t C;
-	uint32_t D;
-	uint32_t total[2];
-	uint32_t buflen;
-	char buffer[128];
-};
-
 /* Initialize structure containing state of computation.
  * (RFC 1321, 3.3: Step 3)
  */
-static void md5_begin(struct md5_ctx_t *ctx)
+void md5_begin(struct md5_ctx_t *ctx)
 {
 	ctx->A = 0x67452301;
 	ctx->B = 0xefcdab89;
@@ -728,7 +706,7 @@ static void md5_hash_bytes(const void *buffer, size_t len, struct md5_ctx_t *ctx
 	}
 }
 
-static void md5_hash(const void *buffer, size_t length, void *md5_ctx)
+void md5_hash(const void *buffer, size_t length, void *md5_ctx)
 {
 	if (length % 64 == 0) {
 		md5_hash_block(buffer, length, md5_ctx);
@@ -745,7 +723,7 @@ static void md5_hash(const void *buffer, size_t length, void *md5_ctx)
  * IMPORTANT: On some systems it is required that RESBUF is correctly
  * aligned for a 32 bits value.
  */
-static void *md5_end(void *resbuf, struct md5_ctx_t *ctx)
+void *md5_end(void *resbuf, struct md5_ctx_t *ctx)
 {
 	/* Take yet unprocessed bytes into account.  */
 	uint32_t bytes = ctx->buflen;
@@ -790,92 +768,3 @@ static void *md5_end(void *resbuf, struct md5_ctx_t *ctx)
 
 	return resbuf;
 }
-#endif	/* CONFIG_MD5SUM */
-
-int hash_fd(int src_fd, const size_t size, const uint8_t hash_algo,
-				   uint8_t * hashval)
-{
-	int result = EXIT_SUCCESS;
-/*	size_t hashed_count = 0; */
-	size_t blocksize = 0;
-	size_t remaining = size;
-	unsigned char *buffer = NULL;
-	void (*hash_fn_ptr)(const void *, size_t, void *) = NULL;
-	void *cx = NULL;
-
-#ifdef CONFIG_SHA1SUM
-	struct sha1_ctx_t sha1_cx;
-#endif
-#ifdef CONFIG_MD5SUM
-	struct md5_ctx_t md5_cx;
-#endif
-
-#ifdef CONFIG_SHA1SUM
-	if (hash_algo == HASH_SHA1) {
-		/* Ensure that BLOCKSIZE is a multiple of 64.  */
-		blocksize = 65536;
-		buffer = xmalloc(blocksize);
-		hash_fn_ptr = sha1_hash;
-		cx = &sha1_cx;
-	}
-#endif
-#ifdef CONFIG_MD5SUM
-	if (hash_algo == HASH_MD5) {
-		blocksize = 4096;
-		buffer = xmalloc(blocksize + 72);
-		hash_fn_ptr = md5_hash;
-		cx = &md5_cx;
-	}
-#endif
-
-	/* Initialize the computation context.  */
-#ifdef CONFIG_SHA1SUM
-	if (hash_algo == HASH_SHA1) {
-		sha1_begin(&sha1_cx);
-	}
-#endif
-#ifdef CONFIG_MD5SUM
-	if (hash_algo == HASH_MD5) {
-		md5_begin(&md5_cx);
-	}
-#endif
-	/* Iterate over full file contents.  */
-	while ((remaining == (size_t) -1) || (remaining > 0)) {
-		size_t read_try;
-		ssize_t read_got;
-
-		if (remaining > blocksize) {
-			read_try = blocksize;
-		} else {
-			read_try = remaining;
-		}
-		read_got = bb_full_read(src_fd, buffer, read_try);
-		if (read_got < 1) {
-			/* count == 0 means short read
-			 * count == -1 means read error */
-			result = read_got - 1;
-			break;
-		}
-		if (remaining != (size_t) -1) {
-			remaining -= read_got;
-		}
-
-		/* Process buffer */
-		hash_fn_ptr(buffer, read_got, cx);
-	}
-
-	/* Finalize and write the hash into our buffer.  */
-#ifdef CONFIG_SHA1SUM
-	if (hash_algo == HASH_SHA1) {
-		sha1_end(hashval, &sha1_cx);
-	}
-#endif
-#ifdef CONFIG_MD5SUM
-	if (hash_algo == HASH_MD5) {
-		md5_end(hashval, &md5_cx);
-	}
-#endif
-
-	free(buffer);
-	return result;
-}

diff --git a/libq/hash_md5_sha1.h b/libq/hash_md5_sha1.h
new file mode 100644
index 0000000..6dbbd44
--- /dev/null
+++ b/libq/hash_md5_sha1.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2005-2020 Gentoo Foundation
+ * Distributed under the terms of the GNU General Public License v2
+ */
+
+#ifndef _HASH_FD_H
+#define _HASH_FD_H 1
+
+/* type to hold the SHA1 context  */
+struct sha1_ctx_t {
+	uint32_t count[2];
+	uint32_t hash[5];
+	uint32_t wbuf[16];
+};
+
+void sha1_begin(struct sha1_ctx_t *ctx);
+void sha1_hash(const void *data, size_t len, void *ctx_v);
+void sha1_end(unsigned char hval[], struct sha1_ctx_t *ctx);
+
+/* Structure to save state of computation between the single steps.  */
+struct md5_ctx_t {
+	uint32_t A;
+	uint32_t B;
+	uint32_t C;
+	uint32_t D;
+	uint32_t total[2];
+	uint32_t buflen;
+	char buffer[128];
+};
+
+void md5_begin(struct md5_ctx_t *ctx);
+void md5_hash(const void *buffer, size_t length, void *md5_ctx);
+void *md5_end(void *resbuf, struct md5_ctx_t *ctx);
+
+#endif

diff --git a/libq/md5_sha1_sum.c b/libq/md5_sha1_sum.c
deleted file mode 100644
index 006a63b..0000000
--- a/libq/md5_sha1_sum.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- *  Copyright (C) 2003 Glenn L. McGrath
- *  Copyright (C) 2003-2004 Erik Andersen
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include "main.h"
-
-#include <fcntl.h>
-#include <limits.h>
-#include <stdio.h>
-#include <inttypes.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "busybox.h"
-#include "xalloc.h"
-#include "hash_fd.h"
-#include "md5_sha1_sum.h"
-
-int hash_cb_default(int fd, const char *filename) {
-	(void)filename;
-
-	return fd;
-}
-
-/* This might be useful elsewhere */
-static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
-									  unsigned char hash_length)
-{
-	int x, len, max;
-	unsigned char *hex_value;
-
-	max = (hash_length * 2) + 2;
-	hex_value = xmalloc(max);
-	for (x = len = 0; x < hash_length; x++) {
-		len += snprintf((char*)(hex_value + len), max - len,
-				"%02x", hash_value[x]);
-	}
-	return (hex_value);
-}
-
-unsigned char *hash_file_at_cb(
-		int dfd,
-		const char *filename,
-		uint8_t hash_algo,
-		hash_cb_t cb)
-{
-	int fd;
-	fd = openat(dfd, filename, O_RDONLY|O_CLOEXEC);
-	if (fd != -1) {
-		static uint8_t hash_value_bin[20];
-		static unsigned char *hash_value;
-		fd = cb(fd, filename);
-		if (hash_fd(fd, -1, hash_algo, hash_value_bin) != -2)
-			hash_value = hash_bin_to_hex(hash_value_bin,
-					hash_algo == HASH_MD5 ? 16 : 20);
-		else
-			hash_value = NULL;
-		close(fd);
-		return hash_value;
-	}
-	return NULL;
-}
-
-unsigned char *hash_file_at(int dfd, const char *filename, uint8_t hash_algo)
-{
-	return hash_file_at_cb(dfd, filename, hash_algo, hash_cb_default);
-}
-
-static unsigned char *hash_file_cb(const char *filename, uint8_t hash_algo, hash_cb_t cb)
-{
-	return hash_file_at_cb(AT_FDCWD, filename, hash_algo, cb);
-}
-
-unsigned char *hash_file(const char *filename, uint8_t hash_algo)
-{
-	return hash_file_cb(filename, hash_algo, hash_cb_default);
-}

diff --git a/libq/md5_sha1_sum.h b/libq/md5_sha1_sum.h
deleted file mode 100644
index 3c682a4..0000000
--- a/libq/md5_sha1_sum.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright 2005-2019 Gentoo Foundation
- * Distributed under the terms of the GNU General Public License v2
- */
-
-#ifndef _MD5_SHA1_SUM_H
-#define _MD5_SHA1_SUM_H 1
-
-/* for HASH_MD5/HASH_SHA1 */
-#include "busybox.h"
-
-/* pass in a fd and get back a fd; filename is for display only */
-typedef int (*hash_cb_t) (int, const char *);
-
-int hash_cb_default(int fd, const char *filename);
-unsigned char *hash_file_at_cb(
-		int dfd,
-		const char *filename,
-		uint8_t hash_algo,
-		hash_cb_t cb);
-unsigned char *hash_file_at(int dfd, const char *filename, uint8_t hash_algo);
-unsigned char *hash_file(const char *filename, uint8_t hash_algo);
-
-#endif

diff --git a/qcheck.c b/qcheck.c
index 72a68a9..9d9a86c 100644
--- a/qcheck.c
+++ b/qcheck.c
@@ -18,7 +18,7 @@
 #include "atom.h"
 #include "contents.h"
 #include "copy_file.h"
-#include "md5_sha1_sum.h"
+#include "hash.h"
 #include "prelink.h"
 #include "tree.h"
 #include "xarray.h"
@@ -233,8 +233,8 @@ qcheck_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 			}
 
 			hash_cb_t hash_cb =
-				state->undo_prelink ? hash_cb_prelink_undo : hash_cb_default;
-			f_digest = (char *)hash_file_at_cb(
+				state->undo_prelink ? hash_cb_prelink_undo : NULL;
+			f_digest = hash_file_at_cb(
 					pkg_ctx->cat_ctx->ctx->portroot_fd,
 					entry->name + 1, hash_algo, hash_cb);
 
@@ -242,7 +242,6 @@ qcheck_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 			 * Can we get a digest of the file? */
 			if (!f_digest) {
 				++num_files_unknown;
-				free(f_digest);
 
 				if (state->qc_update)
 					fprintf(fp_contents_update, "%s\n", buffer);
@@ -283,11 +282,8 @@ qcheck_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 						fprintf(fp_contents_update, "%s\n", buffer);
 				}
 
-				free(f_digest);
 				continue;
 			}
-
-			free(f_digest);
 		}
 
 		/* Validate mtimes */

diff --git a/qmerge.c b/qmerge.c
index 5eec188..103f615 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -24,8 +24,8 @@
 #include "copy_file.h"
 #include "contents.h"
 #include "eat_file.h"
+#include "hash.h"
 #include "human_readable.h"
-#include "md5_sha1_sum.h"
 #include "profile.h"
 #include "rmspace.h"
 #include "scandirat.h"
@@ -828,7 +828,7 @@ merge_tree_at(int fd_src, const char *src, int fd_dst, const char *dst,
 			/* Migrate a file */
 			struct timespec times[2];
 			int fd_srcf, fd_dstf;
-			unsigned char *hash;
+			char *hash;
 			const char *tmpname, *dname;
 			char buf[_Q_PATH_MAX * 2];
 			struct stat ignore;
@@ -838,7 +838,6 @@ merge_tree_at(int fd_src, const char *src, int fd_dst, const char *dst,
 			if (!pretend)
 				fprintf(contents, "obj %s %s %zu""\n",
 						cpath, hash, (size_t)st.st_mtime);
-			free(hash);
 
 			/* Check CONFIG_PROTECT */
 			if (config_protected(cpath + eprefix_len,
@@ -1502,10 +1501,9 @@ pkg_unmerge(tree_pkg_ctx *pkg_ctx, set *keep,
 			case CONTENTS_OBJ:
 				if (protected && unmerge_config_protected) {
 					/* If the file wasn't modified, unmerge it */
-					unsigned char *hash = hash_file_at(portroot_fd,
+					char *hash = hash_file_at(portroot_fd,
 							e->name + 1, HASH_MD5);
 					protected = strcmp(e->digest, (const char *)hash);
-					free(hash);
 				}
 				break;
 
@@ -1623,7 +1621,7 @@ pkg_verify_checksums(char *fname, const struct pkg_t *pkg, const depend_atom *at
 	int ret = 0;
 
 	if (pkg->MD5[0]) {
-		if ((hash = (char*) hash_file(fname, HASH_MD5)) == NULL) {
+		if ((hash = hash_file(fname, HASH_MD5)) == NULL) {
 			errf("hash is NULL for %s", fname);
 		}
 		if (strcmp(hash, pkg->MD5) == 0) {
@@ -1634,11 +1632,10 @@ pkg_verify_checksums(char *fname, const struct pkg_t *pkg, const depend_atom *at
 				warn("MD5:  [%sER%s] (%s) != (%s) %s/%s", RED, NORM, hash, pkg->MD5, atom->CATEGORY, pkg->PF);
 			ret++;
 		}
-		free(hash);
 	}
 
 	if (pkg->SHA1[0]) {
-		hash = (char*) hash_file(fname, HASH_SHA1);
+		hash = hash_file(fname, HASH_SHA1);
 		if (strcmp(hash, pkg->SHA1) == 0) {
 			if (display)
 				qprintf("SHA1: [%sOK%s] %s %s/%s\n", GREEN, NORM, hash, atom->CATEGORY, pkg->PF);
@@ -1647,7 +1644,6 @@ pkg_verify_checksums(char *fname, const struct pkg_t *pkg, const depend_atom *at
 				warn("SHA1: [%sER%s] (%s) != (%s) %s/%s", RED, NORM, hash, pkg->SHA1, atom->CATEGORY, pkg->PF);
 			ret++;
 		}
-		free(hash);
 	}
 
 	if (!pkg->SHA1[0] && !pkg->MD5[0])

diff --git a/qpkg.c b/qpkg.c
index 14e51ce..1494b45 100644
--- a/qpkg.c
+++ b/qpkg.c
@@ -21,8 +21,8 @@
 #include "atom.h"
 #include "basename.h"
 #include "contents.h"
+#include "hash.h"
 #include "human_readable.h"
-#include "md5_sha1_sum.h"
 #include "scandirat.h"
 #include "set.h"
 #include "tree.h"
@@ -228,14 +228,13 @@ qpkg_make(depend_atom *atom)
 			continue;
 		if (check_pkg_install_mask(e->name) != 0)
 			continue;
-		fprintf(out, "%s\n", e->name+1); /* dont output leading / */
+		fprintf(out, "%s\n", e->name+1); /* don't output leading / */
 		if (e->type == CONTENTS_OBJ && verbose) {
-			char *hash = (char *)hash_file(e->name, HASH_MD5);
+			char *hash = hash_file(e->name, HASH_MD5);
 			if (hash != NULL) {
 				if (strcmp(e->digest, hash) != 0)
 					warn("MD5: mismatch expected %s got %s for %s",
 							e->digest, hash, e->name);
-				free(hash);
 			}
 		}
 	}


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [gentoo-commits] proj/portage-utils:master commit in: /, libq/
@ 2024-01-02  7:57 Fabian Groffen
  0 siblings, 0 replies; 23+ messages in thread
From: Fabian Groffen @ 2024-01-02  7:57 UTC (permalink / raw
  To: gentoo-commits

commit:     5b790bbd7eb6e02702e422d9bdcb640b10a3e447
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Tue Jan  2 07:50:51 2024 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Tue Jan  2 07:50:51 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=5b790bbd

libq/hash: switch from OpenSSL/custom to gnulib-based hash impls

OpenSSL deprecated most (if not all) of the hashes we use from it, and
we don't have our own implementations for e.g. SHA512, so switch to
gnulib's versions, which makes this all simpler.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 autogen.sh           |   4 +
 libq/Makefile.am     |   6 -
 libq/hash.c          | 123 +++-----
 libq/hash_md5_sha1.c | 770 ---------------------------------------------------
 libq/hash_md5_sha1.h |  35 ---
 5 files changed, 41 insertions(+), 897 deletions(-)

diff --git a/autogen.sh b/autogen.sh
index df6e574..dc41d69 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -28,6 +28,10 @@ done
 # reload the gnulib code
 PATH=/usr/local/src/gnu/gnulib:${PATH}
 mods="
+	crypto/md5-buffer
+	crypto/sha1-buffer
+	crypto/sha256-buffer
+	crypto/sha512-buffer
 	dirent
 	faccessat
 	fdopendir

diff --git a/libq/Makefile.am b/libq/Makefile.am
index 879d4a7..e65bb47 100644
--- a/libq/Makefile.am
+++ b/libq/Makefile.am
@@ -28,12 +28,6 @@ QFILES = \
 	xsystem.c xsystem.h \
 	$(NULL)
 
-if !QMANIFEST_ENABLED
-if !QTEGRITY_ENABLED
-QFILES += hash_md5_sha1.c hash_md5_sha1.h
-endif
-endif
-
 noinst_LIBRARIES = libq.a
 libq_a_SOURCES = $(QFILES)
 libq_a_CPPFLAGS = \

diff --git a/libq/hash.c b/libq/hash.c
index 4a1202a..9b36bb9 100644
--- a/libq/hash.c
+++ b/libq/hash.c
@@ -12,24 +12,22 @@
 
 #include "main.h"
 
-#ifdef HAVE_SSL
-# include <openssl/md5.h>
-# include <openssl/sha.h>
-#else
-# include "hash_md5_sha1.h"
-#endif
 #ifdef HAVE_BLAKE2B
 # include <blake2.h>
 #endif
 
+#include "md5.h"
+#include "sha1.h"
+#include "sha256.h"
+#include "sha512.h"
+
 #include "hash.h"
 
 void
 hash_hex(char *out, const unsigned char *buf, const int length)
 {
 	switch (length) {
-		/* MD5_DIGEST_LENGTH */
-		case 16:
+		case 16: /* MD5_DIGEST_SIZE */
 			snprintf(out, 32 + 1,
 					"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
 					"%02x%02x%02x%02x%02x%02x",
@@ -39,8 +37,7 @@ hash_hex(char *out, const unsigned char *buf, const int length)
 					buf[15]
 					);
 			break;
-		/* SHA1_DIGEST_LENGTH */
-		case 20:
+		case 20: /* SHA1_DIGEST_SIZE */
 			snprintf(out, 40 + 1,
 					"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
 					"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
@@ -50,8 +47,7 @@ hash_hex(char *out, const unsigned char *buf, const int length)
 					buf[15], buf[16], buf[17], buf[18], buf[19]
 					);
 			break;
-		/* SHA256_DIGEST_LENGTH */
-		case 32:
+		case 32: /* SHA256_DIGEST_SIZE */
 			snprintf(out, 64 + 1,
 					"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
 					"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
@@ -66,8 +62,7 @@ hash_hex(char *out, const unsigned char *buf, const int length)
 					buf[30], buf[31]
 					);
 			break;
-		/* SHA512_DIGEST_LENGTH, WHIRLPOOL_DIGEST_LENGTH, BLAKE2B_OUTBYTES */
-		case 64:
+		case 64: /* SHA512_DIGEST_SIZE, BLAKE2B_OUTBYTES */
 			snprintf(out, 128 + 1,
 					"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
 					"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
@@ -123,22 +118,15 @@ hash_multiple_file_fd(
 		size_t *flen,
 		int hashes)
 {
-	FILE *f;
-	char data[8192];
-	size_t len;
-#ifdef HAVE_SSL
-	MD5_CTX m5;
-	SHA_CTX s1;
-	SHA256_CTX s256;
-	SHA512_CTX s512;
-#else
-	struct md5_ctx_t m5;
-	struct sha1_ctx_t s1;
-	(void)sha256;
-	(void)sha512;
-#endif
+	FILE             *f;
+	char              data[8192];
+	size_t            len;
+	struct md5_ctx    m5;
+	struct sha1_ctx   s1;
+	struct sha256_ctx s256;
+	struct sha512_ctx s512;
 #ifdef HAVE_BLAKE2B
-	blake2b_state bl2b;
+	blake2b_state     bl2b;
 #else
 	(void)blak2b;
 #endif
@@ -147,15 +135,10 @@ hash_multiple_file_fd(
 	if ((f = fdopen(fd, "r")) == NULL)
 		return -1;
 
-#ifdef HAVE_SSL
-	MD5_Init(&m5);
-	SHA1_Init(&s1);
-	SHA256_Init(&s256);
-	SHA512_Init(&s512);
-#else
-	md5_begin(&m5);
-	sha1_begin(&s1);
-#endif
+	md5_init_ctx(&m5);
+	sha1_init_ctx(&s1);
+	sha256_init_ctx(&s256);
+	sha512_init_ctx(&s512);
 #ifdef HAVE_BLAKE2B
 	blake2b_init(&bl2b, BLAKE2B_OUTBYTES);
 #endif
@@ -164,39 +147,26 @@ hash_multiple_file_fd(
 		*flen += len;
 #pragma omp parallel sections
 		{
-#ifdef HAVE_SSL
 #pragma omp section
 			{
 				if (hashes & HASH_MD5)
-					MD5_Update(&m5, data, len);
+					md5_process_bytes(data, len, &m5);
 			}
 #pragma omp section
 			{
 				if (hashes & HASH_SHA1)
-					SHA1_Update(&s1, data, len);
+					sha1_process_bytes(data, len, &s1);
 			}
 #pragma omp section
 			{
 				if (hashes & HASH_SHA256)
-					SHA256_Update(&s256, data, len);
+					sha256_process_bytes(data, len, &s256);
 			}
 #pragma omp section
 			{
 				if (hashes & HASH_SHA512)
-					SHA512_Update(&s512, data, len);
+					sha512_process_bytes(data, len, &s512);
 			}
-#else
-#pragma omp section
-			{
-				if (hashes & HASH_MD5)
-					md5_hash(data, len, &m5);
-			}
-#pragma omp section
-			{
-				if (hashes & HASH_SHA1)
-					sha1_hash(data, len, &s1);
-			}
-#endif
 #ifdef HAVE_BLAKE2B
 #pragma omp section
 			{
@@ -210,57 +180,38 @@ hash_multiple_file_fd(
 
 #pragma omp parallel sections
 	{
-#ifdef HAVE_SSL
 #pragma omp section
 		{
 			if (hashes & HASH_MD5) {
-				unsigned char md5buf[MD5_DIGEST_LENGTH];
-				MD5_Final(md5buf, &m5);
-				hash_hex(md5, md5buf, MD5_DIGEST_LENGTH);
+				unsigned char md5buf[MD5_DIGEST_SIZE];
+				md5_finish_ctx(&m5, md5buf);
+				hash_hex(md5, md5buf, MD5_DIGEST_SIZE);
 			}
 		}
 #pragma omp section
 		{
 			if (hashes & HASH_SHA1) {
-				unsigned char sha1buf[SHA_DIGEST_LENGTH];
-				SHA1_Final(sha1buf, &s1);
-				hash_hex(sha1, sha1buf, SHA_DIGEST_LENGTH);
+				unsigned char sha1buf[SHA1_DIGEST_SIZE];
+				sha1_finish_ctx(&s1, sha1buf);
+				hash_hex(sha1, sha1buf, SHA1_DIGEST_SIZE);
 			}
 		}
 #pragma omp section
 		{
 			if (hashes & HASH_SHA256) {
-				unsigned char sha256buf[SHA256_DIGEST_LENGTH];
-				SHA256_Final(sha256buf, &s256);
-				hash_hex(sha256, sha256buf, SHA256_DIGEST_LENGTH);
+				unsigned char sha256buf[SHA256_DIGEST_SIZE];
+				sha256_finish_ctx(&s256, sha256buf);
+				hash_hex(sha256, sha256buf, SHA256_DIGEST_SIZE);
 			}
 		}
 #pragma omp section
 		{
 			if (hashes & HASH_SHA512) {
-				unsigned char sha512buf[SHA512_DIGEST_LENGTH];
-				SHA512_Final(sha512buf, &s512);
-				hash_hex(sha512, sha512buf, SHA512_DIGEST_LENGTH);
-			}
-		}
-#else
-#pragma omp section
-		{
-			if (hashes & HASH_MD5) {
-				unsigned char md5buf[16];
-				md5_end(md5buf, &m5);
-				hash_hex(md5, md5buf, 16);
+				unsigned char sha512buf[SHA512_DIGEST_SIZE];
+				sha512_finish_ctx(&s512, sha512buf);
+				hash_hex(sha512, sha512buf, SHA512_DIGEST_SIZE);
 			}
 		}
-#pragma omp section
-		{
-			if (hashes & HASH_SHA1) {
-				unsigned char sha1buf[20];
-				sha1_end(sha1buf, &s1);
-				hash_hex(sha1, sha1buf, 20);
-			}
-		}
-#endif
 #ifdef HAVE_BLAKE2B
 #pragma omp section
 		{

diff --git a/libq/hash_md5_sha1.c b/libq/hash_md5_sha1.c
deleted file mode 100644
index bdbe0db..0000000
--- a/libq/hash_md5_sha1.c
+++ /dev/null
@@ -1,770 +0,0 @@
-/*
- *  Based on shasum from http://www.netsw.org/crypto/hash/
- *  Majorly hacked up to use Dr Brian Gladman's sha1 code
- *
- *  Copyright (C) 2003 Glenn L. McGrath
- *  Copyright (C) 2003 Erik Andersen
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include "main.h"
-
-#include <fcntl.h>
-#include <limits.h>
-#include <stdio.h>
-#include <inttypes.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef HAVE_SYS_PARAM_H
-# include <sys/param.h>
-# ifndef __BYTE_ORDER
-#  ifdef BYTE_ORDER
-#   define __BYTE_ORDER BYTE_ORDER
-#  elif defined(_LITTLE_ENDIAN)
-#   define __LITTLE_ENDIAN 1234
-#   define __BIG_ENDIAN 4321
-#   define __BYTE_ORDER __LITTLE_ENDIAN
-#  elif defined(_BIG_ENDIAN)
-#   define __LITTLE_ENDIAN 1234
-#   define __BIG_ENDIAN 4321
-#   define __BYTE_ORDER __BIG_ENDIAN
-#  endif
-# endif
-# ifndef __BIG_ENDIAN
-#  define __BIG_ENDIAN BIG_ENDIAN
-# endif
-# ifndef __LITTLE_ENDIAN
-#  define __LITTLE_ENDIAN LITTLE_ENDIAN
-# endif
-#endif
-
-#include "xalloc.h"
-#include "hash_md5_sha1.h"
-
-/*
- ---------------------------------------------------------------------------
- Begin Dr. Gladman's sha1 code
- ---------------------------------------------------------------------------
-*/
-
-/*
- ---------------------------------------------------------------------------
- Copyright (c) 2002, Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK.
- All rights reserved.
-
- LICENSE TERMS
-
- The free distribution and use of this software in both source and binary
- form is allowed (with or without changes) provided that:
-
-   1. distributions of this source code include the above copyright
-      notice, this list of conditions and the following disclaimer;
-
-   2. distributions in binary form include the above copyright
-      notice, this list of conditions and the following disclaimer
-      in the documentation and/or other associated materials;
-
-   3. the copyright holder's name is not used to endorse products
-      built using this software without specific written permission.
-
- ALTERNATIVELY, provided that this notice is retained in full, this product
- may be distributed under the terms of the GNU General Public License (GPL),
- in which case the provisions of the GPL apply INSTEAD OF those given above.
-
- DISCLAIMER
-
- This software is provided 'as is' with no explicit or implied warranties
- in respect of its properties, including, but not limited to, correctness
- and/or fitness for purpose.
- ---------------------------------------------------------------------------
- Issue Date: 10/11/2002
-
- This is a byte oriented version of SHA1 that operates on arrays of bytes
- stored in memory. It runs at 22 cycles per byte on a Pentium P4 processor
-*/
-
-# define SHA1_BLOCK_SIZE  64
-# define SHA1_DIGEST_SIZE 20
-# define SHA1_HASH_SIZE   SHA1_DIGEST_SIZE
-# define SHA2_GOOD        0
-# define SHA2_BAD         1
-
-# define rotl32(x,n) (((x) << n) | ((x) >> (32 - n)))
-
-# if __BYTE_ORDER == __BIG_ENDIAN
-#  define swap_b32(x) (x)
-# elif defined(bswap_32)
-#  define swap_b32(x) bswap_32(x)
-# else
-#  define swap_b32(x) ((rotl32((x), 8) & 0x00ff00ff) | (rotl32((x), 24) & 0xff00ff00))
-# endif /* __BYTE_ORDER */
-
-# define SHA1_MASK   (SHA1_BLOCK_SIZE - 1)
-
-/* reverse byte order in 32-bit words   */
-#define ch(x,y,z)       ((z) ^ ((x) & ((y) ^ (z))))
-#define parity(x,y,z)   ((x) ^ (y) ^ (z))
-#define maj(x,y,z)      (((x) & (y)) | ((z) & ((x) | (y))))
-
-/* A normal version as set out in the FIPS. This version uses   */
-/* partial loop unrolling and is optimised for the Pentium 4    */
-# define rnd(f,k)    \
-    t = a; a = rotl32(a,5) + f(b,c,d) + e + k + w[i]; \
-    e = d; d = c; c = rotl32(b, 30); b = t
-
-static void sha1_compile(struct sha1_ctx_t *ctx)
-{
-	uint32_t w[80], i, a, b, c, d, e, t;
-
-	/* note that words are compiled from the buffer into 32-bit */
-	/* words in big-endian order so an order reversal is needed */
-	/* here on little endian machines                           */
-	for (i = 0; i < SHA1_BLOCK_SIZE / 4; ++i)
-		w[i] = swap_b32(ctx->wbuf[i]);
-
-	for (i = SHA1_BLOCK_SIZE / 4; i < 80; ++i)
-		w[i] = rotl32(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
-
-	a = ctx->hash[0];
-	b = ctx->hash[1];
-	c = ctx->hash[2];
-	d = ctx->hash[3];
-	e = ctx->hash[4];
-
-	for (i = 0; i < 20; ++i) {
-		rnd(ch, 0x5a827999);
-	}
-
-	for (i = 20; i < 40; ++i) {
-		rnd(parity, 0x6ed9eba1);
-	}
-
-	for (i = 40; i < 60; ++i) {
-		rnd(maj, 0x8f1bbcdc);
-	}
-
-	for (i = 60; i < 80; ++i) {
-		rnd(parity, 0xca62c1d6);
-	}
-
-	ctx->hash[0] += a;
-	ctx->hash[1] += b;
-	ctx->hash[2] += c;
-	ctx->hash[3] += d;
-	ctx->hash[4] += e;
-}
-
-void sha1_begin(struct sha1_ctx_t *ctx)
-{
-	ctx->count[0] = ctx->count[1] = 0;
-	ctx->hash[0] = 0x67452301;
-	ctx->hash[1] = 0xefcdab89;
-	ctx->hash[2] = 0x98badcfe;
-	ctx->hash[3] = 0x10325476;
-	ctx->hash[4] = 0xc3d2e1f0;
-}
-
-/* SHA1 hash data in an array of bytes into hash buffer and call the        */
-/* hash_compile function as required.                                       */
-void sha1_hash(const void *data, size_t len, void *ctx_v)
-{
-	struct sha1_ctx_t *ctx = (struct sha1_ctx_t *) ctx_v;
-	uint32_t pos = (uint32_t) (ctx->count[0] & SHA1_MASK);
-	uint32_t freeb = SHA1_BLOCK_SIZE - pos;
-	const unsigned char *sp = data;
-
-	if ((ctx->count[0] += len) < len)
-		++(ctx->count[1]);
-
-	while (len >= freeb) {	/* tranfer whole blocks while possible  */
-		memcpy(((unsigned char *) ctx->wbuf) + pos, sp, freeb);
-		sp += freeb;
-		len -= freeb;
-		freeb = SHA1_BLOCK_SIZE;
-		pos = 0;
-		sha1_compile(ctx);
-	}
-
-	memcpy(((unsigned char *) ctx->wbuf) + pos, sp, len);
-}
-
-/* SHA1 Final padding and digest calculation  */
-# if __BYTE_ORDER == __LITTLE_ENDIAN
-static uint32_t mask[4] = { 0x00000000, 0x000000ff, 0x0000ffff, 0x00ffffff };
-static uint32_t bits[4] = { 0x00000080, 0x00008000, 0x00800000, 0x80000000 };
-# else
-static uint32_t mask[4] = { 0x00000000, 0xff000000, 0xffff0000, 0xffffff00 };
-static uint32_t bits[4] = { 0x80000000, 0x00800000, 0x00008000, 0x00000080 };
-# endif /* __BYTE_ORDER */
-
-void sha1_end(unsigned char hval[], struct sha1_ctx_t *ctx)
-{
-	uint32_t i, cnt = (uint32_t) (ctx->count[0] & SHA1_MASK);
-
-	/* mask out the rest of any partial 32-bit word and then set    */
-	/* the next byte to 0x80. On big-endian machines any bytes in   */
-	/* the buffer will be at the top end of 32 bit words, on little */
-	/* endian machines they will be at the bottom. Hence the AND    */
-	/* and OR masks above are reversed for little endian systems    */
-	ctx->wbuf[cnt >> 2] =
-		(ctx->wbuf[cnt >> 2] & mask[cnt & 3]) | bits[cnt & 3];
-
-	/* we need 9 or more empty positions, one for the padding byte  */
-	/* (above) and eight for the length count.  If there is not     */
-	/* enough space pad and empty the buffer                        */
-	if (cnt > SHA1_BLOCK_SIZE - 9) {
-		if (cnt < 60)
-			ctx->wbuf[15] = 0;
-		sha1_compile(ctx);
-		cnt = 0;
-	} else				/* compute a word index for the empty buffer positions  */
-		cnt = (cnt >> 2) + 1;
-
-	while (cnt < 14)	/* and zero pad all but last two positions      */
-		ctx->wbuf[cnt++] = 0;
-
-	/* assemble the eight byte counter in the buffer in big-endian  */
-	/* format                                                       */
-
-	ctx->wbuf[14] = swap_b32((ctx->count[1] << 3) | (ctx->count[0] >> 29));
-	ctx->wbuf[15] = swap_b32(ctx->count[0] << 3);
-
-	sha1_compile(ctx);
-
-	/* extract the hash value as bytes in case the hash buffer is   */
-	/* misaligned for 32-bit words                                  */
-
-	for (i = 0; i < SHA1_DIGEST_SIZE; ++i)
-		hval[i] = (unsigned char) (ctx->hash[i >> 2] >> 8 * (~i & 3));
-}
-
-/*
- ---------------------------------------------------------------------------
- End of Dr. Gladman's sha1 code
- ---------------------------------------------------------------------------
-*/
-
-/*
- * md5sum.c - Compute MD5 checksum of files or strings according to the
- *            definition of MD5 in RFC 1321 from April 1992.
- *
- * Copyright (C) 1995-1999 Free Software Foundation, Inc.
- * Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
- *
- *
- * June 29, 2001        Manuel Novoa III
- *
- * Added MD5SUM_SIZE_VS_SPEED configuration option.
- *
- * Current valid values, with data from my system for comparison, are:
- *   (using uClibc and running on linux-2.4.4.tar.bz2)
- *                     user times (sec)  text size (386)
- *     0 (fastest)         1.1                6144
- *     1                   1.4                5392
- *     2                   3.0                5088
- *     3 (smallest)        5.1                4912
- */
-
-# define MD5_DIGEST_SIZE 16
-
-# define MD5SUM_SIZE_VS_SPEED 2
-
-/* Handle endian-ness */
-# if __BYTE_ORDER == __LITTLE_ENDIAN
-#  define SWAP(n) (n)
-# elif defined(bswap_32)
-#  define SWAP(n) bswap_32(n)
-# else
-#  define SWAP(n) ((n << 24) | ((n&65280)<<8) | ((n&16711680)>>8) | (n>>24))
-# endif
-
-# if MD5SUM_SIZE_VS_SPEED == 0
-/* This array contains the bytes used to pad the buffer to the next
-   64-byte boundary.  (RFC 1321, 3.1: Step 1)  */
-static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ...  */  };
-# endif	/* MD5SUM_SIZE_VS_SPEED == 0 */
-
-/* Initialize structure containing state of computation.
- * (RFC 1321, 3.3: Step 3)
- */
-void md5_begin(struct md5_ctx_t *ctx)
-{
-	ctx->A = 0x67452301;
-	ctx->B = 0xefcdab89;
-	ctx->C = 0x98badcfe;
-	ctx->D = 0x10325476;
-
-	ctx->total[0] = ctx->total[1] = 0;
-	ctx->buflen = 0;
-}
-
-/* These are the four functions used in the four steps of the MD5 algorithm
- * and defined in the RFC 1321.  The first function is a little bit optimized
- * (as found in Colin Plumbs public domain implementation).
- * #define FF(b, c, d) ((b & c) | (~b & d))
- */
-# define FF(b, c, d) (d ^ (b & (c ^ d)))
-# define FG(b, c, d) FF (d, b, c)
-# define FH(b, c, d) (b ^ c ^ d)
-# define FI(b, c, d) (c ^ (b | ~d))
-
-/* Starting with the result of former calls of this function (or the
- * initialization function update the context for the next LEN bytes
- * starting at BUFFER.
- * It is necessary that LEN is a multiple of 64!!!
- */
-static void md5_hash_block(const void *buffer, size_t len, struct md5_ctx_t *ctx)
-{
-	uint32_t correct_words[16];
-	const uint32_t *words = buffer;
-	size_t nwords = len / sizeof(uint32_t);
-	const uint32_t *endp = words + nwords;
-
-# if MD5SUM_SIZE_VS_SPEED > 0
-	static const uint32_t C_array[] = {
-		/* round 1 */
-		0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
-		0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
-		0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
-		0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
-		/* round 2 */
-		0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
-		0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8,
-		0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
-		0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
-		/* round 3 */
-		0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
-		0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
-		0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05,
-		0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
-		/* round 4 */
-		0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
-		0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
-		0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
-		0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
-	};
-
-	static const char P_array[] = {
-#  if MD5SUM_SIZE_VS_SPEED > 1
-		0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,	/* 1 */
-#  endif	/* MD5SUM_SIZE_VS_SPEED > 1 */
-		1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12,	/* 2 */
-		5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2,	/* 3 */
-		0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9	/* 4 */
-	};
-
-#  if MD5SUM_SIZE_VS_SPEED > 1
-	static const char S_array[] = {
-		7, 12, 17, 22,
-		5, 9, 14, 20,
-		4, 11, 16, 23,
-		6, 10, 15, 21
-	};
-#  endif	/* MD5SUM_SIZE_VS_SPEED > 1 */
-# endif
-
-	uint32_t A = ctx->A;
-	uint32_t B = ctx->B;
-	uint32_t C = ctx->C;
-	uint32_t D = ctx->D;
-
-	/* First increment the byte count.  RFC 1321 specifies the possible
-	   length of the file up to 2^64 bits.  Here we only compute the
-	   number of bytes.  Do a double word increment.  */
-	ctx->total[0] += len;
-	if (ctx->total[0] < len)
-		++ctx->total[1];
-
-	/* Process all bytes in the buffer with 64 bytes in each round of
-	   the loop.  */
-	while (words < endp) {
-		uint32_t *cwp = correct_words;
-		uint32_t A_save = A;
-		uint32_t B_save = B;
-		uint32_t C_save = C;
-		uint32_t D_save = D;
-
-# if MD5SUM_SIZE_VS_SPEED > 1
-#  define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s)))
-
-		const uint32_t *pc;
-		const char *pp;
-		const char *ps;
-		int i;
-		uint32_t temp;
-
-		for (i = 0; i < 16; i++) {
-			cwp[i] = SWAP(words[i]);
-		}
-		words += 16;
-
-#  if MD5SUM_SIZE_VS_SPEED > 2
-		pc = C_array;
-		pp = P_array;
-		ps = S_array - 4;
-
-		for (i = 0; i < 64; i++) {
-			if ((i & 0x0f) == 0)
-				ps += 4;
-			temp = A;
-			switch (i >> 4) {
-			case 0:
-				temp += FF(B, C, D);
-				break;
-			case 1:
-				temp += FG(B, C, D);
-				break;
-			case 2:
-				temp += FH(B, C, D);
-				break;
-			case 3:
-				temp += FI(B, C, D);
-			}
-			temp += cwp[(int) (*pp++)] + *pc++;
-			CYCLIC(temp, ps[i & 3]);
-			temp += B;
-			A = D;
-			D = C;
-			C = B;
-			B = temp;
-		}
-#  else
-		pc = C_array;
-		pp = P_array;
-		ps = S_array;
-
-		for (i = 0; i < 16; i++) {
-			temp = A + FF(B, C, D) + cwp[(int) (*pp++)] + *pc++;
-			CYCLIC(temp, ps[i & 3]);
-			temp += B;
-			A = D;
-			D = C;
-			C = B;
-			B = temp;
-		}
-
-		ps += 4;
-		for (i = 0; i < 16; i++) {
-			temp = A + FG(B, C, D) + cwp[(int) (*pp++)] + *pc++;
-			CYCLIC(temp, ps[i & 3]);
-			temp += B;
-			A = D;
-			D = C;
-			C = B;
-			B = temp;
-		}
-		ps += 4;
-		for (i = 0; i < 16; i++) {
-			temp = A + FH(B, C, D) + cwp[(int) (*pp++)] + *pc++;
-			CYCLIC(temp, ps[i & 3]);
-			temp += B;
-			A = D;
-			D = C;
-			C = B;
-			B = temp;
-		}
-		ps += 4;
-		for (i = 0; i < 16; i++) {
-			temp = A + FI(B, C, D) + cwp[(int) (*pp++)] + *pc++;
-			CYCLIC(temp, ps[i & 3]);
-			temp += B;
-			A = D;
-			D = C;
-			C = B;
-			B = temp;
-		}
-
-#  endif	/* MD5SUM_SIZE_VS_SPEED > 2 */
-# else
-		/* First round: using the given function, the context and a constant
-		   the next context is computed.  Because the algorithms processing
-		   unit is a 32-bit word and it is determined to work on words in
-		   little endian byte order we perhaps have to change the byte order
-		   before the computation.  To reduce the work for the next steps
-		   we store the swapped words in the array CORRECT_WORDS.  */
-
-#  define OP(a, b, c, d, s, T)	\
-      do	\
-        {	\
-	  a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T;	\
-	  ++words;	\
-	  CYCLIC (a, s);	\
-	  a += b;	\
-        }	\
-      while (0)
-
-		/* It is unfortunate that C does not provide an operator for
-		   cyclic rotation.  Hope the C compiler is smart enough.  */
-		/* gcc 2.95.4 seems to be --aaronl */
-#  define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s)))
-
-		/* Before we start, one word to the strange constants.
-		   They are defined in RFC 1321 as
-
-		   T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64
-		 */
-
-#  if MD5SUM_SIZE_VS_SPEED == 1
-		const uint32_t *pc;
-		const char *pp;
-		int i;
-#  endif	/* MD5SUM_SIZE_VS_SPEED */
-
-		/* Round 1.  */
-#  if MD5SUM_SIZE_VS_SPEED == 1
-		pc = C_array;
-		for (i = 0; i < 4; i++) {
-			OP(A, B, C, D, 7, *pc++);
-			OP(D, A, B, C, 12, *pc++);
-			OP(C, D, A, B, 17, *pc++);
-			OP(B, C, D, A, 22, *pc++);
-		}
-#  else
-		OP(A, B, C, D, 7, 0xd76aa478);
-		OP(D, A, B, C, 12, 0xe8c7b756);
-		OP(C, D, A, B, 17, 0x242070db);
-		OP(B, C, D, A, 22, 0xc1bdceee);
-		OP(A, B, C, D, 7, 0xf57c0faf);
-		OP(D, A, B, C, 12, 0x4787c62a);
-		OP(C, D, A, B, 17, 0xa8304613);
-		OP(B, C, D, A, 22, 0xfd469501);
-		OP(A, B, C, D, 7, 0x698098d8);
-		OP(D, A, B, C, 12, 0x8b44f7af);
-		OP(C, D, A, B, 17, 0xffff5bb1);
-		OP(B, C, D, A, 22, 0x895cd7be);
-		OP(A, B, C, D, 7, 0x6b901122);
-		OP(D, A, B, C, 12, 0xfd987193);
-		OP(C, D, A, B, 17, 0xa679438e);
-		OP(B, C, D, A, 22, 0x49b40821);
-#  endif	/* MD5SUM_SIZE_VS_SPEED == 1 */
-
-		/* For the second to fourth round we have the possibly swapped words
-		   in CORRECT_WORDS.  Redefine the macro to take an additional first
-		   argument specifying the function to use.  */
-#  undef OP
-#  define OP(f, a, b, c, d, k, s, T)	\
-      do	\
-	{	\
-	  a += f (b, c, d) + correct_words[k] + T;	\
-	  CYCLIC (a, s);	\
-	  a += b;	\
-	}	\
-      while (0)
-
-		/* Round 2.  */
-#  if MD5SUM_SIZE_VS_SPEED == 1
-		pp = P_array;
-		for (i = 0; i < 4; i++) {
-			OP(FG, A, B, C, D, (int) (*pp++), 5, *pc++);
-			OP(FG, D, A, B, C, (int) (*pp++), 9, *pc++);
-			OP(FG, C, D, A, B, (int) (*pp++), 14, *pc++);
-			OP(FG, B, C, D, A, (int) (*pp++), 20, *pc++);
-		}
-#  else
-		OP(FG, A, B, C, D, 1, 5, 0xf61e2562);
-		OP(FG, D, A, B, C, 6, 9, 0xc040b340);
-		OP(FG, C, D, A, B, 11, 14, 0x265e5a51);
-		OP(FG, B, C, D, A, 0, 20, 0xe9b6c7aa);
-		OP(FG, A, B, C, D, 5, 5, 0xd62f105d);
-		OP(FG, D, A, B, C, 10, 9, 0x02441453);
-		OP(FG, C, D, A, B, 15, 14, 0xd8a1e681);
-		OP(FG, B, C, D, A, 4, 20, 0xe7d3fbc8);
-		OP(FG, A, B, C, D, 9, 5, 0x21e1cde6);
-		OP(FG, D, A, B, C, 14, 9, 0xc33707d6);
-		OP(FG, C, D, A, B, 3, 14, 0xf4d50d87);
-		OP(FG, B, C, D, A, 8, 20, 0x455a14ed);
-		OP(FG, A, B, C, D, 13, 5, 0xa9e3e905);
-		OP(FG, D, A, B, C, 2, 9, 0xfcefa3f8);
-		OP(FG, C, D, A, B, 7, 14, 0x676f02d9);
-		OP(FG, B, C, D, A, 12, 20, 0x8d2a4c8a);
-#  endif	/* MD5SUM_SIZE_VS_SPEED == 1 */
-
-		/* Round 3.  */
-#  if MD5SUM_SIZE_VS_SPEED == 1
-		for (i = 0; i < 4; i++) {
-			OP(FH, A, B, C, D, (int) (*pp++), 4, *pc++);
-			OP(FH, D, A, B, C, (int) (*pp++), 11, *pc++);
-			OP(FH, C, D, A, B, (int) (*pp++), 16, *pc++);
-			OP(FH, B, C, D, A, (int) (*pp++), 23, *pc++);
-		}
-#  else
-		OP(FH, A, B, C, D, 5, 4, 0xfffa3942);
-		OP(FH, D, A, B, C, 8, 11, 0x8771f681);
-		OP(FH, C, D, A, B, 11, 16, 0x6d9d6122);
-		OP(FH, B, C, D, A, 14, 23, 0xfde5380c);
-		OP(FH, A, B, C, D, 1, 4, 0xa4beea44);
-		OP(FH, D, A, B, C, 4, 11, 0x4bdecfa9);
-		OP(FH, C, D, A, B, 7, 16, 0xf6bb4b60);
-		OP(FH, B, C, D, A, 10, 23, 0xbebfbc70);
-		OP(FH, A, B, C, D, 13, 4, 0x289b7ec6);
-		OP(FH, D, A, B, C, 0, 11, 0xeaa127fa);
-		OP(FH, C, D, A, B, 3, 16, 0xd4ef3085);
-		OP(FH, B, C, D, A, 6, 23, 0x04881d05);
-		OP(FH, A, B, C, D, 9, 4, 0xd9d4d039);
-		OP(FH, D, A, B, C, 12, 11, 0xe6db99e5);
-		OP(FH, C, D, A, B, 15, 16, 0x1fa27cf8);
-		OP(FH, B, C, D, A, 2, 23, 0xc4ac5665);
-#  endif	/* MD5SUM_SIZE_VS_SPEED == 1 */
-
-		/* Round 4.  */
-#  if MD5SUM_SIZE_VS_SPEED == 1
-		for (i = 0; i < 4; i++) {
-			OP(FI, A, B, C, D, (int) (*pp++), 6, *pc++);
-			OP(FI, D, A, B, C, (int) (*pp++), 10, *pc++);
-			OP(FI, C, D, A, B, (int) (*pp++), 15, *pc++);
-			OP(FI, B, C, D, A, (int) (*pp++), 21, *pc++);
-		}
-#  else
-		OP(FI, A, B, C, D, 0, 6, 0xf4292244);
-		OP(FI, D, A, B, C, 7, 10, 0x432aff97);
-		OP(FI, C, D, A, B, 14, 15, 0xab9423a7);
-		OP(FI, B, C, D, A, 5, 21, 0xfc93a039);
-		OP(FI, A, B, C, D, 12, 6, 0x655b59c3);
-		OP(FI, D, A, B, C, 3, 10, 0x8f0ccc92);
-		OP(FI, C, D, A, B, 10, 15, 0xffeff47d);
-		OP(FI, B, C, D, A, 1, 21, 0x85845dd1);
-		OP(FI, A, B, C, D, 8, 6, 0x6fa87e4f);
-		OP(FI, D, A, B, C, 15, 10, 0xfe2ce6e0);
-		OP(FI, C, D, A, B, 6, 15, 0xa3014314);
-		OP(FI, B, C, D, A, 13, 21, 0x4e0811a1);
-		OP(FI, A, B, C, D, 4, 6, 0xf7537e82);
-		OP(FI, D, A, B, C, 11, 10, 0xbd3af235);
-		OP(FI, C, D, A, B, 2, 15, 0x2ad7d2bb);
-		OP(FI, B, C, D, A, 9, 21, 0xeb86d391);
-#  endif	/* MD5SUM_SIZE_VS_SPEED == 1 */
-# endif	/* MD5SUM_SIZE_VS_SPEED > 1 */
-
-		/* Add the starting values of the context.  */
-		A += A_save;
-		B += B_save;
-		C += C_save;
-		D += D_save;
-	}
-
-	/* Put checksum in context given as argument.  */
-	ctx->A = A;
-	ctx->B = B;
-	ctx->C = C;
-	ctx->D = D;
-}
-
-/* Starting with the result of former calls of this function (or the
- * initialization function update the context for the next LEN bytes
- * starting at BUFFER.
- * It is NOT required that LEN is a multiple of 64.
- */
-
-static void md5_hash_bytes(const void *buffer, size_t len, struct md5_ctx_t *ctx)
-{
-	/* When we already have some bits in our internal buffer concatenate
-	   both inputs first.  */
-	if (ctx->buflen != 0) {
-		size_t left_over = ctx->buflen;
-		size_t add = 128 - left_over > len ? len : 128 - left_over;
-
-		memcpy(&ctx->buffer[left_over], buffer, add);
-		ctx->buflen += add;
-
-		if (left_over + add > 64) {
-			md5_hash_block(ctx->buffer, (left_over + add) & ~63, ctx);
-			/* The regions in the following copy operation cannot overlap.  */
-			memcpy(ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
-				   (left_over + add) & 63);
-			ctx->buflen = (left_over + add) & 63;
-		}
-
-		buffer = (const char *) buffer + add;
-		len -= add;
-	}
-
-	/* Process available complete blocks.  */
-	if (len > 64) {
-		md5_hash_block(buffer, len & ~63, ctx);
-		buffer = (const char *) buffer + (len & ~63);
-		len &= 63;
-	}
-
-	/* Move remaining bytes in internal buffer.  */
-	if (len > 0) {
-		memcpy(ctx->buffer, buffer, len);
-		ctx->buflen = len;
-	}
-}
-
-void md5_hash(const void *buffer, size_t length, void *md5_ctx)
-{
-	if (length % 64 == 0) {
-		md5_hash_block(buffer, length, md5_ctx);
-	} else {
-		md5_hash_bytes(buffer, length, md5_ctx);
-	}
-}
-
-/* Process the remaining bytes in the buffer and put result from CTX
- * in first 16 bytes following RESBUF.  The result is always in little
- * endian byte order, so that a byte-wise output yields to the wanted
- * ASCII representation of the message digest.
- *
- * IMPORTANT: On some systems it is required that RESBUF is correctly
- * aligned for a 32 bits value.
- */
-void *md5_end(void *resbuf, struct md5_ctx_t *ctx)
-{
-	/* Take yet unprocessed bytes into account.  */
-	uint32_t bytes = ctx->buflen;
-	uint32_t swap_bytes;
-	size_t pad;
-
-	/* Now count remaining bytes.  */
-	ctx->total[0] += bytes;
-	if (ctx->total[0] < bytes)
-		++ctx->total[1];
-
-	pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
-# if MD5SUM_SIZE_VS_SPEED > 0
-	memset(&ctx->buffer[bytes], 0, pad);
-	ctx->buffer[bytes] = 0x80;
-# else
-	memcpy(&ctx->buffer[bytes], fillbuf, pad);
-# endif	/* MD5SUM_SIZE_VS_SPEED > 0 */
-
-	/* Put the 64-bit file length in *bits* at the end of the buffer.
-	   Use memcpy to avoid aliasing problems.  On most systems, this
-	   will be optimized away to the same code.  */
-	swap_bytes = SWAP(ctx->total[0] << 3);
-	memcpy(&ctx->buffer[bytes + pad], &swap_bytes, sizeof(swap_bytes));
-	swap_bytes = SWAP(((ctx->total[1] << 3) | (ctx->total[0] >> 29)));
-	memcpy(&ctx->buffer[bytes + pad + 4], &swap_bytes, sizeof(swap_bytes));
-
-	/* Process last bytes.  */
-	md5_hash_block(ctx->buffer, bytes + pad + 8, ctx);
-
-	/* Put result from CTX in first 16 bytes following RESBUF.  The result is
-	 * always in little endian byte order, so that a byte-wise output yields
-	 * to the wanted ASCII representation of the message digest.
-	 *
-	 * IMPORTANT: On some systems it is required that RESBUF is correctly
-	 * aligned for a 32 bits value.
-	 */
-	((uint32_t *) resbuf)[0] = SWAP(ctx->A);
-	((uint32_t *) resbuf)[1] = SWAP(ctx->B);
-	((uint32_t *) resbuf)[2] = SWAP(ctx->C);
-	((uint32_t *) resbuf)[3] = SWAP(ctx->D);
-
-	return resbuf;
-}

diff --git a/libq/hash_md5_sha1.h b/libq/hash_md5_sha1.h
deleted file mode 100644
index 6dbbd44..0000000
--- a/libq/hash_md5_sha1.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2005-2020 Gentoo Foundation
- * Distributed under the terms of the GNU General Public License v2
- */
-
-#ifndef _HASH_FD_H
-#define _HASH_FD_H 1
-
-/* type to hold the SHA1 context  */
-struct sha1_ctx_t {
-	uint32_t count[2];
-	uint32_t hash[5];
-	uint32_t wbuf[16];
-};
-
-void sha1_begin(struct sha1_ctx_t *ctx);
-void sha1_hash(const void *data, size_t len, void *ctx_v);
-void sha1_end(unsigned char hval[], struct sha1_ctx_t *ctx);
-
-/* Structure to save state of computation between the single steps.  */
-struct md5_ctx_t {
-	uint32_t A;
-	uint32_t B;
-	uint32_t C;
-	uint32_t D;
-	uint32_t total[2];
-	uint32_t buflen;
-	char buffer[128];
-};
-
-void md5_begin(struct md5_ctx_t *ctx);
-void md5_hash(const void *buffer, size_t length, void *md5_ctx);
-void *md5_end(void *resbuf, struct md5_ctx_t *ctx);
-
-#endif


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2024-01-02  7:57 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-15 13:52 [gentoo-commits] proj/portage-utils:master commit in: /, libq/ Fabian Groffen
  -- strict thread matches above, loose matches on Subject: below --
2024-01-02  7:57 Fabian Groffen
2020-05-16 18:27 Fabian Groffen
2020-01-05 16:08 Fabian Groffen
2020-01-04 19:48 Fabian Groffen
2020-01-01 17:54 Fabian Groffen
2019-07-14 13:09 Fabian Groffen
2019-05-07  6:19 Fabian Groffen
2019-05-06 17:33 Fabian Groffen
2019-05-02 15:48 Fabian Groffen
2018-05-18 16:58 Fabian Groffen
2016-12-29  2:25 Mike Frysinger
2016-12-29  2:25 Mike Frysinger
2016-02-14  1:26 Mike Frysinger
2016-02-14  1:26 Mike Frysinger
2015-11-28  2:44 Mike Frysinger
2015-11-28  2:44 Mike Frysinger
2015-02-24  1:26 Mike Frysinger
2014-03-21  5:32 Mike Frysinger
2014-03-10  8:45 Mike Frysinger
2014-03-10  6:00 Mike Frysinger
2014-03-08  5:51 Mike Frysinger
2014-03-08  5:51 Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox