commit: debecebe010e3c33e594ec5745e591982095d62b
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Sep 26 13:53:18 2019 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Sep 26 13:53:18 2019 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=debecebe
libq/atom: add atom_compar_cb, qsort compatible comparator function
use this new function from libq/tree where it was moved from
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
libq/atom.c | 17 +++++++++++++++++
libq/atom.h | 1 +
libq/tree.c | 9 +--------
3 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/libq/atom.c b/libq/atom.c
index 8f564eb..f80bb7d 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -843,3 +843,20 @@ atom_format(const char *format, const depend_atom *atom)
{
return atom_format_r(_atom_buf, sizeof(_atom_buf), format, atom);
}
+
+/* qsort compatible callback function */
+inline int
+atom_compar_cb(const void *l, const void *r)
+{
+ const depend_atom *al = l;
+ const depend_atom *ar = r;
+
+ switch (atom_compare(al, ar)) {
+ case EQUAL: return 0;
+ case NEWER: return -1;
+ case OLDER: return 1;
+ default: return strcmp(al->PN, ar->PN);
+ }
+
+ /* unreachable */
+}
diff --git a/libq/atom.h b/libq/atom.h
index 43397ad..a5175b0 100644
--- a/libq/atom.h
+++ b/libq/atom.h
@@ -104,5 +104,6 @@ char *atom_format_r(char *buf, size_t buflen,
const char *format, const depend_atom *atom);
char *atom_to_string(depend_atom *a);
char *atom_format(const char *format, const depend_atom *atom);
+int atom_compar_cb(const void *l, const void *r);
#endif
diff --git a/libq/tree.c b/libq/tree.c
index 8caed00..a8baabe 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -320,14 +320,7 @@ tree_pkg_compar(const void *l, const void *r)
depend_atom *al = tree_get_atom(pl, false);
depend_atom *ar = tree_get_atom(pr, false);
- switch (atom_compare(al, ar)) {
- case EQUAL: return 0;
- case NEWER: return -1;
- case OLDER: return 1;
- default: return strcmp(al->PN, ar->PN);
- }
-
- /* unreachable */
+ return atom_compar_cb(al, ar);
}
static tree_pkg_ctx *