From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id B0DDD138334 for ; Thu, 26 Sep 2019 14:06:52 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id CDB7BE09A6; Thu, 26 Sep 2019 14:06:51 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B4592E09A6 for ; Thu, 26 Sep 2019 14:06:51 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 21AE534B5D9 for ; Thu, 26 Sep 2019 14:06:50 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id B29ED7FE for ; Thu, 26 Sep 2019 14:06:47 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1569505998.debecebe010e3c33e594ec5745e591982095d62b.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/ X-VCS-Repository: proj/portage-utils X-VCS-Files: libq/atom.c libq/atom.h libq/tree.c X-VCS-Directories: libq/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: debecebe010e3c33e594ec5745e591982095d62b X-VCS-Branch: master Date: Thu, 26 Sep 2019 14:06:47 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 9be1eab7-7d73-4fe4-a6f0-3a994f9d7f2e X-Archives-Hash: acc001d7ab9c839790f00e6796c8c994 commit: debecebe010e3c33e594ec5745e591982095d62b Author: Fabian Groffen gentoo org> AuthorDate: Thu Sep 26 13:53:18 2019 +0000 Commit: Fabian Groffen gentoo 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 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 *