From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MWT77-0008QS-4C for qemu-devel@nongnu.org; Thu, 30 Jul 2009 06:43:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MWT72-0008Kj-DT for qemu-devel@nongnu.org; Thu, 30 Jul 2009 06:43:56 -0400 Received: from [199.232.76.173] (port=54161 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MWT70-0008KB-Ir for qemu-devel@nongnu.org; Thu, 30 Jul 2009 06:43:51 -0400 Received: from mx2.redhat.com ([66.187.237.31]:38592) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MWT6z-0005Tl-ME for qemu-devel@nongnu.org; Thu, 30 Jul 2009 06:43:50 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n6UAhmj9009522 for ; Thu, 30 Jul 2009 06:43:48 -0400 From: Gerd Hoffmann Date: Thu, 30 Jul 2009 12:43:37 +0200 Message-Id: <1248950621-22249-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1248950621-22249-1-git-send-email-kraxel@redhat.com> References: <1248950621-22249-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 1/5] QemuOpts: add some functions List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann qemu_opt_foreach: loop over all QemuOpts entries. qemu_opts_id: return QemuOpts id. Signed-off-by: Gerd Hoffmann --- qemu-option.c | 19 +++++++++++++++++++ qemu-option.h | 4 ++++ 2 files changed, 23 insertions(+), 0 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index 73c2175..86c0b09 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -606,6 +606,20 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value) return 0; } +int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque, + int abort_on_failure) +{ + QemuOpt *opt; + int rc = 0; + + TAILQ_FOREACH(opt, &opts->head, next) { + rc = func(opt->name, opt->str, opaque); + if (abort_on_failure && rc != 0) + break; + } + return rc; +} + QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id) { QemuOpts *opts; @@ -662,6 +676,11 @@ int qemu_opts_set(QemuOptsList *list, const char *id, return qemu_opt_set(opts, name, value); } +const char *qemu_opts_id(QemuOpts *opts) +{ + return opts->id; +} + void qemu_opts_del(QemuOpts *opts) { QemuOpt *opt; diff --git a/qemu-option.h b/qemu-option.h index 428c947..56c7eac 100644 --- a/qemu-option.h +++ b/qemu-option.h @@ -104,11 +104,15 @@ int qemu_opt_get_bool(QemuOpts *opts, const char *name, int defval); uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval); uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval); int qemu_opt_set(QemuOpts *opts, const char *name, const char *value); +typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void *opaque); +int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque, + int abort_on_failure); QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id); QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exists); int qemu_opts_set(QemuOptsList *list, const char *id, const char *name, const char *value); +const char *qemu_opts_id(QemuOpts *opts); void qemu_opts_del(QemuOpts *opts); QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *firstname); -- 1.6.2.5