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 AC320138335 for ; Mon, 18 Mar 2019 13:14:11 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DEEA5E0977; Mon, 18 Mar 2019 13:14:10 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (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 A3C7BE0977 for ; Mon, 18 Mar 2019 13:14:10 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (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 DEE89335D45 for ; Mon, 18 Mar 2019 13:14:08 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 8692F570 for ; Mon, 18 Mar 2019 13:14:07 +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: <1552658575.43d8c0998aafc279cdfdb18c715ae945e945138a.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: q.c qmerge.c X-VCS-Directories: / X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 43d8c0998aafc279cdfdb18c715ae945e945138a X-VCS-Branch: master Date: Mon, 18 Mar 2019 13:14:07 +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: 1fcb3614-fcff-437c-b8bf-9927fca17fbb X-Archives-Hash: 4f5fe52c54523d8295ea6be543b9800f commit: 43d8c0998aafc279cdfdb18c715ae945e945138a Author: Fabian Groffen gentoo org> AuthorDate: Fri Mar 15 14:02:55 2019 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Fri Mar 15 14:02:55 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=43d8c099 q.c: move run_applet_l to its only consumer qmerge.c Signed-off-by: Fabian Groffen gentoo.org> q.c | 45 ++++----------------------------------------- qmerge.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/q.c b/q.c index 64aa284..30a295d 100644 --- a/q.c +++ b/q.c @@ -87,7 +87,8 @@ int q_main(int argc, char **argv) case 'M': modpath = optarg; break; case 'm': if (optarg) { - const char *path = initialize_flat(optarg, CACHE_METADATA, true); + const char *path = + initialize_flat(optarg, CACHE_METADATA, true); if (USE_CLEANUP) free((void *)path); reinitialize_metacache = -1; @@ -149,7 +150,8 @@ int q_main(int argc, char **argv) for (i = 1; applets[i].desc; ++i) { int r = symlinkat(prog, fd, applets[i].name); if (!quiet) - printf(" %s ...\t[%s]\n", applets[i].name, r ? strerror(errno) : "OK"); + printf(" %s ...\t[%s]\n", + applets[i].name, r ? strerror(errno) : "OK"); if (r && errno != EEXIST) ret = 1; } @@ -184,42 +186,3 @@ int q_main(int argc, char **argv) return (func)(argc - 1, argv); } -static int run_applet_l(const char *arg, ...) -{ - int (*applet)(int, char **); - va_list ap; - int ret, optind_saved, argc; - char **argv; - const char *argv0_saved; - - optind_saved = optind; - argv0_saved = argv0; - - applet = lookup_applet(arg); - if (!applet) - return -1; - - /* This doesn't NULL terminate argv, but you should be using argc */ - va_start(ap, arg); - argc = 0; - argv = NULL; - while (arg) { - argv = xrealloc(argv, sizeof(*argv) * ++argc); - argv[argc - 1] = xstrdup(arg); - arg = va_arg(ap, const char *); - } - va_end(ap); - - optind = 0; - argv0 = argv[0]; - ret = applet(argc, argv); - - while (argc--) - free(argv[argc]); - free(argv); - - optind = optind_saved; - argv0 = argv0_saved; - - return ret; -} diff --git a/qmerge.c b/qmerge.c index aec51be..c90f786 100644 --- a/qmerge.c +++ b/qmerge.c @@ -105,6 +105,46 @@ static int pkg_unmerge(q_vdb_pkg_ctx *, set *, int, char **, int, char **); static struct pkg_t *grab_binpkg_info(const char *); static char *find_binpkg(const char *); +static int run_applet_l(const char *arg, ...) +{ + int (*applet)(int, char **); + va_list ap; + int ret, optind_saved, argc; + char **argv; + const char *argv0_saved; + + optind_saved = optind; + argv0_saved = argv0; + + applet = lookup_applet(arg); + if (!applet) + return -1; + + /* This doesn't NULL terminate argv, but you should be using argc */ + va_start(ap, arg); + argc = 0; + argv = NULL; + while (arg) { + argv = xrealloc(argv, sizeof(*argv) * ++argc); + argv[argc - 1] = xstrdup(arg); + arg = va_arg(ap, const char *); + } + va_end(ap); + + optind = 0; + argv0 = argv[0]; + ret = applet(argc, argv); + + while (argc--) + free(argv[argc]); + free(argv); + + optind = optind_saved; + argv0 = argv0_saved; + + return ret; +} + static void fetch(const char *destdir, const char *src) {